Browse Source

Merge pull request 'mp' (#46) from mp into develop

Reviewed-on: https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/pulls/46
tall
wally 4 years ago
parent
commit
97e2989675
  1. 2
      .eslintrc.js
  2. 6
      CHANGELOG.md
  3. 4
      package.json
  4. 20
      src/App.vue
  5. 2
      src/apis/tall.js
  6. 1
      src/components/Upload/Upload.vue
  7. 2
      src/config/user.js
  8. 4
      src/manifest.json
  9. 48
      src/mixins/userAuth.js
  10. 8
      src/pages/index/index.vue
  11. 5
      src/pages/phone-bind/phone-bind.vue
  12. 15
      src/store/index.js
  13. 60
      src/utils/upload.js

2
.eslintrc.js

@ -41,8 +41,8 @@ module.exports = {
Vue: true,
VueRouter: true,
Vuex: true,
axios: true,
_: true,
uni: true,
wx: true,
},
};

6
CHANGELOG.md

@ -1,4 +1,4 @@
# 0.1.0 (2021-08-31)
# 0.1.0 (2021-09-09)
### 🌟 新功能
范围|描述|commitId
@ -23,6 +23,7 @@
- | 上传逻辑变化 | 3ff1dc2
- | 任务状态时间显示 | 56f5183
- | 任务进行中状态数字 | 27b7326
- | 修改小程序id | 4206bf2
- | 全局插件及默认插件位置修改 | 6c80d08
- | 升级版本v3.1.0;tailwindcss添加class | 9ef05e1
- | 向右箭头图标变化 | 8e9ca55
@ -54,6 +55,7 @@
- | 细节调整,添加project-webview | 4d9050b
- | 绑定手机号 | 52e0352
- | 缓存修改 | 63e1f0d
- | 获取用户收取那,提交用户信息 | a3c54f1
- | 角色栏实现 | 94cd671
- | 设置小红点 | 9316bcb
- | 距调整pc端 | 5069aa1
@ -193,6 +195,7 @@
- | 修改代码格式 | 14123d7
- | 修改定期任务骨架屏高度 | 909a734
- | 小红点api缓存修改 | e992343
- | 提交本地代码 | e0cf2ed
- | 插件查询及展示 | 4dba770
- | 整理代码 | 7a55315
- | 日历的更改 | 7353ac8
@ -220,6 +223,7 @@
信息配置 | 配置eslint等配置 | 7421443
- | 修复不能build的问题 | 0b7b91e
- | 删除多余的构建的命令 | 3f4eb2f
- | 添加mp-weixin的构建命令 | 3776a67
范围|描述|commitId

4
package.json

@ -12,8 +12,8 @@
"dev:h5-pro": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve --mode production",
"build:h5-test": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build --mode development",
"build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build --mode production",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build --mode production",
"build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build --mode production",
"cz": "npm run log && git add . && git cz",
"dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
"dev:custom": "cross-env NODE_ENV=development uniapp-cli custom",

20
src/App.vue

@ -5,9 +5,10 @@ export default {
async onLaunch(options) {
console.log('options: ', options);
this.checkNetwork(); //
this.getSystemInfo(); //
/* #ifdef MP-WEIXIN */
await this.signin();
this.initSocket();
/* #endif */
/* #ifdef H5 */
@ -23,9 +24,8 @@ export default {
this.noPhone(data.phone);
}
}
// FIXME:
this.initSocket();
/* #endif */
this.initSocket();
},
computed: {
@ -36,7 +36,7 @@ export default {
methods: {
...mapActions('user', ['getToken']),
...mapActions('socket', ['initSocket']),
...mapMutations(['setNetworkConnected']),
...mapMutations(['setNetworkConnected', 'setSystemInfo']),
...mapMutations('user', ['setToken', 'setUser']),
// store
@ -79,6 +79,18 @@ export default {
this.$u.route('/pages/phone-bind/phone-bind');
}
},
//
getSystemInfo() {
uni.getSystemInfo({
success: result => {
this.setSystemInfo(result);
},
fail: error => {
console.error('getSystemInfo fail:', error);
},
});
},
},
};
</script>

2
src/apis/tall.js

@ -30,6 +30,8 @@ const install = (Vue, vm) => {
vm.$u.api.getToken = userId => vm.$u.get(`${tall}/users/userId`, { userId });
// 绑定手机号
vm.$u.api.phoneBind = (phone, smsCode) => vm.$u.http.post(`${tall}/users/binding`, { phone, smsCode });
// 修改用户信息
vm.$u.api.updateUserInfo = params => vm.$u.http.post(`${tall}/users/userInfo`, params);
// 获取项目列表
vm.$u.api.getProjects = (startTime, endTime) => vm.$u.post(`${tall}/project/query`, { startTime, endTime });

1
src/components/Upload/Upload.vue

@ -27,6 +27,7 @@ export default {
});
}, 2000);
} catch (error) {
console.log('error: ', error);
this.$emit('error', error);
}
},

2
src/config/user.js

@ -22,7 +22,7 @@ export const mp = () => {
const params = {
client: uni.$t.user.clients['mp'],
type: uni.$t.user.types['mp'],
data: { identifier: res.code },
data: { identifier: res.code, credential: 'tall' },
};
resolve(params);
} else {

4
src/manifest.json

@ -1,6 +1,6 @@
{
"name": "TALL",
"appid": "wx356e01c7eb01d55d",
"appid": "wxf72a76c2ea24a472",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
@ -57,7 +57,7 @@
/* */
},
"mp-weixin": {
"appid": "wx356e01c7eb01d55d",
"appid": "wxf72a76c2ea24a472",
"setting": {
"urlCheck": false
},

48
src/mixins/userAuth.js

@ -0,0 +1,48 @@
import { mapMutations, mapState } from 'vuex';
import { waitTokenRequest } from '@/utils/cacheAndRequest';
export default {
computed: mapState('user', ['token', 'user']),
methods: {
...mapMutations('user', ['setUser']),
// 获取授权
openAuth() {
if (this.user && this.user.wxInfo && this.user.wxInfo.nickname) return; // 用户信息里有微信信息就不用再获取了
if (this.token) {
this.updateUserInfo();
} else {
waitTokenRequest(this.updateUserInfo);
}
},
// 弹出授权框
// 用户允许后 提交微信用户信息
updateUserInfo() {
/* #ifdef MP-WEIXIN */
uni.getUserProfile({
desc: 'TALL仅需要获取您的基本用户信息',
success: async res => {
const { avatarUrl, city, country, gender, language, nickName, province } = res.userInfo;
const data = await this.$u.api.updateUserInfo({
city,
country,
headImgUrl: avatarUrl,
language,
nickname: nickName,
province,
sex: gender,
});
console.log('data: ', data);
const { user } = this;
user.wxInfo = data;
this.setUser(user);
},
fail: error => {
console.log('error: ', error);
},
});
/* #endif */
},
},
};

8
src/pages/index/index.vue

@ -1,10 +1,12 @@
<template>
<view class="flex flex-col h-full bg-gray-50">
<view class="flex flex-col h-full bg-gray-50" @click="openAuth">
<view class="relative" @touchmove="onMove">
<!-- 日历 -->
<Calendar @selected-change="onDateChange" :show-back="true" ref="calendar" @handleFindPoint="handleFindPoint" />
<!-- 上传 导入wbs -->
<Upload @success="onUploadSuccess" @error="onUploadError" />
<!-- #ifdef H5 -->
<!-- #endif -->
</view>
<!-- 项目列表 -->
@ -17,10 +19,12 @@
<script>
import { mapState, mapMutations } from 'vuex';
import UserAuthMixin from '@/mixins/userAuth';
let prevY = 0;
export default {
mixins: [UserAuthMixin],
data() {
return {
calendar: null,
@ -28,7 +32,7 @@ export default {
};
},
computed: mapState('user', ['token']),
computed: mapState('user', ['token', 'user']),
watch: {
token(value) {

5
src/pages/phone-bind/phone-bind.vue

@ -1,5 +1,5 @@
<template>
<view class="wrap">
<view class="wrap" @click="openAuth">
<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
<!-- 手机号 -->
<u-form-item :rightIconStyle="{ color: '#888', fontSize: '32rpx' }" label="手机号码" prop="phone" label-width="160">
@ -27,7 +27,10 @@
</template>
<script>
import UserAuthMixin from '@/mixins/userAuth';
export default {
mixins: [UserAuthMixin],
data() {
return {
model: {

15
src/store/index.js

@ -9,6 +9,7 @@ import user from './user/index';
const state = {
networkConnected: true, // 网络是否连接
forceUseStorage: false, // 强制启用storage
systemInfo: null, // 系统设备信息
};
const getters = {
@ -17,6 +18,11 @@ const getters = {
useStorage({ networkConnected, forceUseStorage }) {
return forceUseStorage || !networkConnected;
},
// 是不是微信平台
isWeChat({ systemInfo }) {
return !(!systemInfo || !systemInfo.host || systemInfo.host.env !== 'WeChat');
},
};
const mutations = {
@ -28,6 +34,15 @@ const mutations = {
setNetworkConnected(state, networkConnected) {
state.networkConnected = networkConnected;
},
/**
* 设置系统信息的数据
* @param {object} state
* @param {object | null} data 获取到的数据
*/
setSystemInfo(state, data) {
state.systemInfo = data;
},
};
Vue.use(Vuex);

60
src/utils/upload.js

@ -1,3 +1,49 @@
// H5选择文件
const chooseFileH5 = (extension = ['.xls', '.xlsx']) => {
return new Promise((resolve, reject) => {
uni.chooseFile({
count: 1, //默认100
extension,
success(res) {
resolve(res.tempFilePaths[0]);
},
fail() {
reject('上传失败');
},
});
});
};
// 微信选择文件 从客户端会话选择文件。
const chooseFileWeixin = (extension = ['.xls', '.xlsx']) => {
return new Promise((resolve, reject) => {
wx.chooseMessageFile({
count: 1,
extension,
type: 'file',
success(res) {
resolve(res.tempFiles[0].path);
},
fail() {
reject('上传失败');
},
});
});
};
// 选择文件
const chooseFile = (extension = ['.xls', '.xlsx']) => {
let fn = null;
/* #ifdef H5 */
fn = chooseFileH5(extension);
/* #endif */
/* #ifdef MP-WEIXIN */
fn = chooseFileWeixin(extension);
/* #endif */
return fn;
};
export default {
/**
* 上传单个文件
@ -16,10 +62,9 @@ export default {
if (!token) {
return reject('用户未登录,请登录后重试');
}
uni.chooseFile({
count: 1, //默认100
extension,
success: res => {
chooseFile(extension)
.then(filePath => {
console.log('filePath: ', filePath);
if (!timer) {
timer = setTimeout(() => {
uni.$t.ui.showLoading('正在上传...');
@ -29,7 +74,7 @@ export default {
// 开始上传
uni.uploadFile({
url,
filePath: res.tempFilePaths[0],
filePath,
name,
formData,
header: { Authorization: `Bearer ${token}` },
@ -54,12 +99,11 @@ export default {
reject(error);
},
});
},
fail: error => {
})
.catch(error => {
clearTimeout(timer);
uni.hideLoading();
reject(error);
},
});
});
},

Loading…
Cancel
Save