|
|
@@ -2,16 +2,17 @@
|
|
|
* @Author: wanglj wanglijie@dashoo.cn
|
|
|
* @Date: 2025-03-17 14:46:02
|
|
|
* @LastEditors: wanglj wanglijie@dashoo.cn
|
|
|
- * @LastEditTime: 2025-03-18 19:50:12
|
|
|
+ * @LastEditTime: 2025-03-19 15:18:54
|
|
|
* @FilePath: \labsop-h5\src\view\stores\userInfo.ts
|
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
*/
|
|
|
-import { defineStore } from 'pinia';
|
|
|
-import { useSystemApi } from '/@/api/system/index';
|
|
|
+import { defineStore } from 'pinia'
|
|
|
+import { useSystemApi } from '/@/api/system/index'
|
|
|
|
|
|
-import to from 'await-to-js';
|
|
|
-import { showNotify } from 'vant';
|
|
|
-const sysApi = useSystemApi();
|
|
|
+import to from 'await-to-js'
|
|
|
+import { showDialog, showNotify } from 'vant'
|
|
|
+import wx from 'weixin-js-sdk'
|
|
|
+const sysApi = useSystemApi()
|
|
|
|
|
|
/**
|
|
|
* 用户信息
|
|
|
@@ -21,22 +22,36 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
state: (): UserInfosState => ({
|
|
|
userInfos: {
|
|
|
id: 0,
|
|
|
+ avatar: '',
|
|
|
+ userName: '',
|
|
|
nickName: '',
|
|
|
sex: '',
|
|
|
- userName: '',
|
|
|
- photo: '',
|
|
|
phone: '',
|
|
|
+ photo: '',
|
|
|
time: 0,
|
|
|
roles: [],
|
|
|
authBtnList: [],
|
|
|
+ deptName: '',
|
|
|
+ deptId: '',
|
|
|
+ userRoles: '',
|
|
|
+ userRoleNames: '',
|
|
|
+ userType: '',
|
|
|
+ creditScore: 0,
|
|
|
+ pgName: ''
|
|
|
},
|
|
|
- openId: ''
|
|
|
+ openId: '',
|
|
|
+ sdkConfig: {
|
|
|
+ app_id: '',
|
|
|
+ timestamp: 0,
|
|
|
+ nonce_str: '',
|
|
|
+ signature: ''
|
|
|
+ }
|
|
|
}),
|
|
|
actions: {
|
|
|
async setUserInfos() {
|
|
|
// 存储用户信息到浏览器缓存
|
|
|
- const userInfos = <UserInfos>await this.getApiUserInfo();
|
|
|
- this.userInfos = userInfos;
|
|
|
+ const userInfos = <UserInfos>await this.getApiUserInfo()
|
|
|
+ this.userInfos = userInfos
|
|
|
},
|
|
|
// 模拟接口数据
|
|
|
// https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP
|
|
|
@@ -44,32 +59,34 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
// eslint-disable-next-line no-async-promise-executor
|
|
|
return new Promise(async (resolve) => {
|
|
|
// 模拟数据,请求接口时,记得删除多余代码及对应依赖的引入
|
|
|
- const [err, res]: ToResponse = await to(sysApi.getUserByUserName());
|
|
|
- if (err) return;
|
|
|
- const { userInfo, perms, roles, projectGroupRes } = res?.data;
|
|
|
+ const [err, res]: ToResponse = await to(sysApi.getUserByUserName())
|
|
|
+ if (err) return
|
|
|
+ const { userInfo, perms, roles, projectGroupRes } = res?.data
|
|
|
// 模拟数据
|
|
|
- let defaultRoles: Array<string> = [];
|
|
|
- let defaultAuthBtnList: Array<string> = [];
|
|
|
+ let defaultRoles: Array<string> = []
|
|
|
+ let defaultAuthBtnList: Array<string> = []
|
|
|
// admin 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
|
|
- let adminRoles: Array<string> = ['admin'];
|
|
|
+ let adminRoles: Array<string> = ['admin']
|
|
|
// admin 按钮权限标识
|
|
|
- let adminAuthBtnList: Array<string> = ['btn.add', 'btn.del', 'btn.edit', 'btn.link'];
|
|
|
+ let adminAuthBtnList: Array<string> = ['btn.add', 'btn.del', 'btn.edit', 'btn.link']
|
|
|
// test 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
|
|
- let testRoles: Array<string> = ['common'];
|
|
|
+ let testRoles: Array<string> = ['common']
|
|
|
// test 按钮权限标识
|
|
|
- let testAuthBtnList: Array<string> = ['btn.add', 'btn.link'];
|
|
|
+ let testAuthBtnList: Array<string> = ['btn.add', 'btn.link']
|
|
|
// 不同用户模拟不同的用户权限
|
|
|
if (userInfo.userName === 'admin') {
|
|
|
- defaultRoles = adminRoles;
|
|
|
- defaultAuthBtnList = adminAuthBtnList;
|
|
|
+ defaultRoles = adminRoles
|
|
|
+ defaultAuthBtnList = adminAuthBtnList
|
|
|
} else {
|
|
|
- defaultRoles = testRoles;
|
|
|
- defaultAuthBtnList = testAuthBtnList;
|
|
|
+ defaultRoles = testRoles
|
|
|
+ defaultAuthBtnList = testAuthBtnList
|
|
|
}
|
|
|
- const userRoles = roles?.map((item: RowRoleType) => item.roleCode);
|
|
|
+ const userRoles = roles?.map((item: RowRoleType) => item.roleCode)
|
|
|
+ const userRoleNames = roles?.map((item: RowRoleType) => item.roleName)
|
|
|
// 用户信息模拟数据
|
|
|
const userInfos = {
|
|
|
id: userInfo.id,
|
|
|
+ avatar: userInfo.avatar,
|
|
|
userName: userInfo.userName,
|
|
|
nickName: userInfo.nickName,
|
|
|
sex: userInfo.sex,
|
|
|
@@ -81,20 +98,57 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
deptName: userInfo.deptName,
|
|
|
deptId: userInfo.deptId,
|
|
|
userRoles: userRoles?.join() || '',
|
|
|
+ userRoleNames: userRoleNames.join('、'),
|
|
|
userType: userInfo.userType,
|
|
|
- projectGroupRes
|
|
|
- };
|
|
|
- resolve(userInfos);
|
|
|
- });
|
|
|
+ creditScore: userInfo.creditScore,
|
|
|
+ pgName: projectGroupRes.pgName
|
|
|
+ }
|
|
|
+ resolve(userInfos)
|
|
|
+ })
|
|
|
},
|
|
|
async setOpenId(code: string) {
|
|
|
const [err, res]: ToResponse = await to(sysApi.getOpenId({ code }))
|
|
|
- if(err || res?.data?.code != '200') return
|
|
|
- // showNotify({
|
|
|
- // message: code + JSON.stringify(res.data),
|
|
|
- // type: 'success'
|
|
|
- // })
|
|
|
+ if (err || res?.data?.code != '200') return
|
|
|
this.openId = res?.data?.data?.openid || ''
|
|
|
+ },
|
|
|
+ async getSdkConfig() {
|
|
|
+ const [err, res]: ToResponse = await to(sysApi.getSDKTicket({ url: window.location.href }))
|
|
|
+ if (err) return
|
|
|
+ this.sdkConfig = res?.data
|
|
|
+ wx.config({
|
|
|
+ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
+ appId: this.sdkConfig.app_id, // 必填,公众号的唯一标识
|
|
|
+ timestamp: this.sdkConfig.timestamp, // 必填,生成签名的时间戳
|
|
|
+ nonceStr: this.sdkConfig.nonce_str, // 必填,生成签名的随机串
|
|
|
+ signature: this.sdkConfig.signature, // 必填,签名
|
|
|
+ jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表
|
|
|
+ })
|
|
|
+ // wx.ready(function () {
|
|
|
+ // showDialog({
|
|
|
+ // title: '提示',
|
|
|
+ // message: '初始化sdk成功',
|
|
|
+ // showCancelButton: false
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // wx.error(function () {
|
|
|
+ // showDialog({
|
|
|
+ // title: '提示',
|
|
|
+ // message: '初始化sdk失败',
|
|
|
+ // showCancelButton: false
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ },
|
|
|
+ scanCode() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ wx.scanQRCode({
|
|
|
+ needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
|
|
|
+ scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
|
|
|
+ success: function (res: any) {
|
|
|
+ var result: string = res.resultStr // 当needResult 为 1 时,扫码返回的结果
|
|
|
+ return resolve(result)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
- },
|
|
|
-});
|
|
|
+ }
|
|
|
+})
|