Browse Source

feat: app.vue

test2
xuesinan 4 years ago
parent
commit
970cf9a364
  1. 29
      App.vue
  2. 1
      CHANGELOG.md
  3. 49
      apis/tall.js
  4. 12
      apis/wbs.js
  5. 8
      common/js/config.js
  6. 31
      main.js
  7. 3
      package.json
  8. 8
      pages/user/login.vue
  9. 2
      store/user/actions.js
  10. 7
      store/user/mutations.js
  11. 36
      utils/cacheAndRequest.js
  12. 61
      utils/tall.js
  13. 40
      utils/time.js
  14. 5
      utils/ui.js
  15. 14
      utils/upload.js

29
App.vue

@ -1,10 +1,8 @@
<script>
import { ref, computed } from 'vue';
import store from '@/store/index.js';
import ui from '@/utils/ui.js';
import storage from '@/utils/storage.js';
import { ref, computed } from 'vue';
import store from '@/store/index.js';
export default {
export default {
setup() {
@ -25,7 +23,7 @@ export default {
// token userId
if (!options.query || !options.query.u) {
// u (userId)
ui.showToast('缺少用户信息参数');
this.$ui.showToast('缺少用户信息参数');
} else {
const data = await store.dispatch('user/getTokenByUserId', options.query.u);
this.noPhone(data.phone);
@ -63,6 +61,23 @@ export default {
});
},
//
async signin() {
try {
const data = await uni.$u.api.signin();
if (data && data.token) {
store.commit('user/setUser', data);
store.commit('user/setToken', data.token);
this.noPhone(data.phone);
} else {
this.$ui.showToast('返回数据异常');
}
} catch (error) {
console.error('error: ', error);
this.$ui.showToast(error || '登录失败');
}
},
/**
* 没有手机号 跳转绑定手机号的界面
* @param {string} phone
@ -73,7 +88,7 @@ export default {
}
},
}
}
}
</script>
<style lang="scss">

1
CHANGELOG.md

@ -3,6 +3,7 @@
### 🌟 新功能
范围|描述|commitId
--|--|--
- | 使用uview完成api请求 | [1b3efd8](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/1b3efd8)
- | first commit | [8dc26de](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/8dc26de)
- | vue3 | [12ed2ad](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/12ed2ad)

49
apis/tall.js

@ -1,46 +1,45 @@
const apiUrl = 'https://test.tall.wiki/gateway'; // 测试
// const apiUrl = 'https://www.tall.wiki/gateway'; // 生产
import Config from '@/common/js/config.js'
const apiUrl = Config.apiUrl;
const tall = `${apiUrl}/tall3/v3.0`;
// 登录
// export const login = {
// async index(params) {
// try {
// const data = await uni.$u.http.post(`${tall}/users/signin`, params);
// return data;
// } catch (error) {
// throw new Error(error);
// }
// },
// };
export const login = {
async index(params) {
try {
const data = await uni.$u.http.post(`${tall}/users/signin`, params);
return data;
} catch (error) {
throw new Error(error);
}
},
};
export function setupTall(app) {
uni.$u.api = { ...uni.$u.api } || {};
// 登录
// app.config.globalProperties.$u.api.signin = params => login.index(params);
uni.$u.api.signin = params => login.index(params);
// 获取图片验证码
// app.config.globalProperties.$u.api.getImageCode = () => app.config.globalProperties.$u.get(`${tall}/users/code`);
uni.$u.api.getImageCode = () => uni.$u.get(`${tall}/users/code`);
// 获取短信验证码
// app.config.globalProperties.$u.api.getSmsCode = params => app.config.globalProperties.$u.get(`${tall}/users/smscode`, params);
uni.$u.api.getSmsCode = params => uni.$u.get(`${tall}/users/smscode`, params);
// 根据userId获取token
uni.$u.api.getToken = userId => uni.$u.get(`${tall}/users/userId`, { userId });
// 绑定手机号
// app.config.globalProperties.$u.api.phoneBind = (phone, smsCode) => app.config.globalProperties.$u.http.post(`${tall}/users/binding`, { phone, smsCode });
uni.$u.api.phoneBind = (phone, smsCode) => uni.$u.http.post(`${tall}/users/binding`, { phone, smsCode });
// 是否合并账号
// app.config.globalProperties.$u.api.phoneMerge = (phone, isMerge) => app.config.globalProperties.$u.http.post(`${tall}/users/merge`, { phone, isMerge });
uni.$u.api.phoneMerge = (phone, isMerge) => uni.$u.http.post(`${tall}/users/merge`, { phone, isMerge });
// 修改用户信息
// app.config.globalProperties.$u.api.updateUserInfo = params => app.config.globalProperties.$u.http.post(`${tall}/users/userInfo`, params);
uni.$u.api.updateUserInfo = params => uni.$u.http.post(`${tall}/users/userInfo`, params);
// 获取项目列表
// app.config.globalProperties.$u.api.getProjects = (startTime, endTime) => app.config.globalProperties.$u.post(`${tall}/project/query`, { startTime, endTime });
uni.$u.api.getProjects = (startTime, endTime) => uni.$u.post(`${tall}/project/query`, { startTime, endTime });
// 查询日历是否有小红点
// app.config.globalProperties.$u.api.findRedPoint = (startTime, endTime) => app.config.globalProperties.$u.post(`${tall}/project/day`, { startTime, endTime });
uni.$u.api.findRedPoint = (startTime, endTime) => uni.$u.post(`${tall}/project/day`, { startTime, endTime });
// 设置项目顺序
// app.config.globalProperties.$u.api.setProjectSort = params => app.config.globalProperties.$u.post(`${tall}/project/setProjectSort`, params);
uni.$u.api.setProjectSort = params => uni.$u.post(`${tall}/project/setProjectSort`, params);
// 设置项目父子结构
// app.config.globalProperties.$u.api.setProjectRelation = params => app.config.globalProperties.$u.post(`${tall}/project/setProjectRelation`, params);
uni.$u.api.setProjectRelation = params => uni.$u.post(`${tall}/project/setProjectRelation`, params);
// 删除某个项目
// app.config.globalProperties.$u.api.delProject = projectId => app.config.globalProperties.$u.post(`${tall}/project/deleteProject`, { projectId });
uni.$u.api.delProject = projectId => uni.$u.post(`${tall}/project/deleteProject`, { projectId });
}

12
apis/wbs.js

@ -1,7 +1,7 @@
const install = (Vue, vm) => {
vm.$u.api = { ...vm.$u.api } || {};
// 导入wbs
vm.$u.api.import = formData => vm.$t.chooseAndUpload(`${uni.$t.domain}/wbs`, formData);
};
import Config from "@/common/js/config.js"
export default { install };
export function setupWbs(app) {
uni.$u.api = { ...uni.$u.api } || {};
// 导入wbs
uni.$u.api.import = formData => this.$upload.chooseAndUpload(`${Config.apiUrl}/wbs`, formData);
}

8
common/js/config.js

@ -1,7 +1,7 @@
var config = {
baseUrl: 'https://test.tall.wiki',
apiUrl: 'https://test.tall.wiki/gateway',
msgUrl: 'wss://test.tall.wiki/websocket/message/v4.0/ws';
msgUrl: 'wss://test.tall.wiki/websocket/message/v4.0/ws',
projectPath: 'https://test.tall.wiki/tall-project',
// baseUrl: 'https://www.tall.wiki',
@ -10,12 +10,6 @@ var config = {
// projectPath: 'https://www.tall.wiki/tall-project',
version: 'v4.0.0'
VUE_APP_BASE_URL=
VUE_APP_API_URL=
VUE_APP_MSG_URL=
VUE_APP_PROJECT_PATH=
};
export default config;

31
main.js

@ -2,25 +2,36 @@ import { createSSRApp } from 'vue';
import App from './App';
import uView from './uni_modules/vk-uview-ui'; // 引入 uView UI
import store from "./store";
// import tall from '@/apis/tall.js';
// import request from '@/utils/request.js';
// import uTall from '@/utils/tall.js';
import { setupHttp } from '@/utils/request.js'
import { setupTall } from '@/apis/tall.js'
import { setupHttp } from '@/utils/request.js';
import { setupTall } from '@/apis/tall.js';
import { setupWbs } from '@/apis/wbs.js'
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import cache from '@/utils/cache.js';
import cacheAndRequest from '@/utils/cacheAndRequest.js';
import storage from '@/utils/storage.js';
import time from '@/utils/time.js';
import ui from '@/utils/ui.js';
import upload from '@/utils/upload.js';
export function createApp() {
const app = createSSRApp(App)
app.use(uView); // 使用 uView UI
app.use(store);
// app.use(request);
// app.use(tall);
// app.use(uTall);
setupHttp(app);
setupTall(app);
setupWbs(app);
dayjs.locale('zh-cn');
// app.config.globalProperties.$tall = tall;
// app.config.globalProperties.$request = request;
app.config.globalProperties.$cache = cache;
app.config.globalProperties.$catchReq = cacheAndRequest;
app.config.globalProperties.$storage = storage;
app.config.globalProperties.$time = time;
app.config.globalProperties.$ui = ui;
app.config.globalProperties.$upload = upload;
return {
app

3
package.json

@ -4,7 +4,8 @@
"description": "",
"main": "main.js",
"dependencies": {
"axios": "^0.24.0"
"axios": "^0.24.0",
"dayjs": "^1.10.7"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.8.1",

8
pages/user/login.vue

@ -0,0 +1,8 @@
<template>
</template>
<script>
</script>
<style>
</style>

2
store/user/actions.js

@ -1,4 +1,3 @@
// import { getToken } from '@/apis/tall.js';
import ui from '@/utils/ui.js';
const actions = {
@ -14,7 +13,6 @@ const actions = {
commit('setUser', res);
return res;
} catch (error) {
console.log('222', error);
ui.showToast(error.msg || '获取个人信息失败');
}
},

7
store/user/mutations.js

@ -9,9 +9,6 @@ const mutations = {
setToken(state, token) {
state.token = token || '';
storage.setStorageSync('anyringToken', token || '');
// uni.$t.storage.setStorageSync('anyringToken', token || '');
// sessionStorage.setItem('token', user.token);
// sessionStorage.setItem('user', JSON.stringify(user));
},
/**
@ -21,7 +18,9 @@ const mutations = {
*/
setUser(state, user) {
if (!user) return;
state.user = { ...user };
state.user = {
...user
};
storage.setStorageSync('user', JSON.stringify(user));
},
};

36
utils/cacheAndRequest.js

@ -24,8 +24,7 @@ export default {
let remote = false;
if (store.getters.useStorage) {
// 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache
.getProjectsByDay(startTime, endTime)
uni.$t.cache.getProjectsByDay(startTime, endTime)
.then(data => {
!remote && fn(null, data);
})
@ -33,8 +32,7 @@ export default {
}
waitTokenRequest(() => {
// 拿到api数据后 再用api的数据
uni.$u.api
.getProjects(startTime, endTime)
uni.$u.api.getProjects(startTime, endTime)
.then(data => {
remote = true;
fn(null, data);
@ -52,8 +50,7 @@ export default {
findShowRole(params, fn) {
let remote = false;
// 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache
.getShowRole(params.projectId)
uni.$t.cache.getShowRole(params.projectId)
.then(data => {
!remote && fn(null, data);
})
@ -61,8 +58,7 @@ export default {
waitTokenRequest(() => {
// 拿到api数据后 再用api的数据
uni.$u.api
.findShowRole(params)
uni.$u.api.findShowRole(params)
.then(data => {
remote = true;
fn(null, data);
@ -80,8 +76,7 @@ export default {
getRegularTask(params, fn) {
let remote = false;
// 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache
.getStorageRegularTask(params)
uni.$t.cache.getStorageRegularTask(params)
.then(data => {
console.log('cache data: ', data);
!remote && fn(null, data);
@ -90,8 +85,7 @@ export default {
waitTokenRequest(() => {
// 拿到api数据后 再用api的数据
uni.$u.api
.getRegularTask(params)
uni.$u.api.getRegularTask(params)
.then(data => {
console.log('api data: ', uni.$u.deepClone(data));
remote = true;
@ -111,8 +105,7 @@ export default {
getPermanent(params, fn) {
let remote = false;
// 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache
.getStoragePermanent(params)
uni.$t.cache.getStoragePermanent(params)
.then(data => {
!remote && fn(null, data);
})
@ -120,8 +113,7 @@ export default {
waitTokenRequest(() => {
// 拿到api数据后 再用api的数据
uni.$u.api
.getPermanent(params)
uni.$u.api.getPermanent(params)
.then(data => {
remote = true;
fn(null, data);
@ -139,8 +131,7 @@ export default {
getGlobal(params, fn) {
let remote = false;
// 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache
.getDailyTask(params)
uni.$t.cache.getDailyTask(params)
.then(data => {
!remote && fn(null, data);
})
@ -148,8 +139,7 @@ export default {
waitTokenRequest(() => {
// 拿到api数据后 再用api的数据
uni.$u.api
.getGlobal(params)
uni.$u.api.getGlobal(params)
.then(data => {
remote = true;
fn(null, data);
@ -167,8 +157,7 @@ export default {
getOtherPlugin(params, fn) {
let remote = false;
// 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache
.getPlugin(params.pluginId)
uni.$t.cache.getPlugin(params.pluginId)
.then(data => {
!remote && fn(null, data);
})
@ -176,8 +165,7 @@ export default {
waitTokenRequest(() => {
// 拿到api数据后 再用api的数据
uni.$u.api
.getOtherPlugin(params)
uni.$u.api.getOtherPlugin(params)
.then(data => {
remote = true;
fn(null, data);

61
utils/tall.js

@ -1,35 +1,36 @@
import app from '@/config/app.js';
import cache from '@/utils/cache.js';
import cacheAndRequest from '@/utils/cacheAndRequest.js';
import storage from '@/utils/storage.js';
import time from '@/utils/time.js';
import ui from '@/utils/ui.js';
import upload from '@/utils/upload.js';
import user from '@/config/user.js';
import zIndex from '@/config/zIndex.js';
// import app from '@/config/app.js';
// import cache from '@/utils/cache.js';
// import cacheAndRequest from '@/utils/cacheAndRequest.js';
// import storage from '@/utils/storage.js';
// import time from '@/utils/time.js';
// import ui from '@/utils/ui.js';
// import upload from '@/utils/upload.js';
// import user from '@/config/user.js';
// import zIndex from '@/config/zIndex.js';
const gateway = process.env.VUE_APP_API_URL;
// const gateway = process.env.VUE_APP_API_URL;
const $t = {
zIndex, // 定位元素层级
app, // app级别的相关配置
storage, // 本地存储storage封装
time, // 时间处理
ui, // ui界面提示相关
chooseAndUpload: upload.chooseAndUpload, // 选择并上传单个文件相关的封装
domain: `${gateway}/defaultwbs`,
cache, // 本地存储相关
$q: cacheAndRequest,
user, // 用户相关配置
};
// const $t = {
// zIndex, // 定位元素层级
// app, // app级别的相关配置
// storage, // 本地存储storage封装
// time, // 时间处理
// ui, // ui界面提示相关
// chooseAndUpload: upload.chooseAndUpload, // 选择并上传单个文件相关的封装
// domain: `${gateway}/defaultwbs`,
// cache, // 本地存储相关
// $q: cacheAndRequest,
// user, // 用户相关配置
// };
uni.$t = $t;
// uni.$t = $t;
const install = Vue => {
// Vue.prototype.$t = $t;
Vue.config.globalProperties.$t = $t;
};
// const install = Vue => {
// // Vue.prototype.$t = $t;
export default {
install
};
// Vue.config.globalProperties.$t = $t;
// };
// export default {
// install
// };

40
utils/time.js

@ -1,12 +1,12 @@
import dayjs from 'dayjs';
const advancedFormat = require('dayjs/plugin/advancedFormat');
const weekOfYear = require('dayjs/plugin/weekOfYear');
const duration = require('dayjs/plugin/duration');
// const advancedFormat = require('dayjs/plugin/advancedFormat');
// const weekOfYear = require('dayjs/plugin/weekOfYear');
// const duration = require('dayjs/plugin/duration');
dayjs.extend(advancedFormat);
dayjs.extend(weekOfYear);
dayjs.extend(duration);
// dayjs.extend(advancedFormat);
// dayjs.extend(weekOfYear);
// dayjs.extend(duration);
/**
* 格式化数字
@ -97,7 +97,8 @@ const setTimestampToStr = timestamp => {
const validateTimeIsToday = time => {
const timeDate = new Date(time);
const date = new Date();
return timeDate.getFullYear() === date.getFullYear() && timeDate.getMonth() === date.getMonth() && timeDate.getDate() === date.getDate();
return timeDate.getFullYear() === date.getFullYear() && timeDate.getMonth() === date.getMonth() && timeDate
.getDate() === date.getDate();
};
/**
@ -315,8 +316,19 @@ const formatStartTimeToCycleTime = (cycle, time) => {
*/
const computeDurationText = leftTime => {
try {
if (leftTime < 0) return { num: 0, time: null };
const { years, months, days, hours, minutes, seconds, milliseconds } = dayjs.duration(leftTime).$d;
if (leftTime < 0) return {
num: 0,
time: null
};
const {
years,
months,
days,
hours,
minutes,
seconds,
milliseconds
} = dayjs.duration(leftTime).$d;
let num = 0;
let time = 1000;
@ -341,10 +353,16 @@ const computeDurationText = leftTime => {
} else {
time = null;
}
return { num, time };
return {
num,
time
};
} catch (error) {
console.log('🚀 ~ file: time.js ~ line 335 ~ computeDurationText ~ error', error);
return { num: 0, time: null };
return {
num: 0,
time: null
};
}
};

5
utils/ui.js

@ -46,10 +46,7 @@ export default {
title,
content,
showCancel,
success: ({
confirm,
cancel
}) => {
success: ({ confirm, cancel }) => {
confirm && resolve();
cancel && reject();
},

14
utils/upload.js

@ -77,13 +77,21 @@ export default {
filePath,
name,
formData,
header: { Authorization: `Bearer ${token}` },
success: ({ data, statusCode }) => {
header: {
Authorization: `Bearer ${token}`
},
success: ({
data,
statusCode
}) => {
clearTimeout(timer);
uni.hideLoading();
if (statusCode === 200 && data) {
const { code, msg } = JSON.parse(data);
const {
code,
msg
} = JSON.parse(data);
if (code !== 200) {
reject(msg);
} else {

Loading…
Cancel
Save