gaoluyang
2026-04-11 bd5a7ca6133eeddb8fed41ee2eb1c0c0874db91d
中兴实强app
1.部署修改
已修改6个文件
198 ■■■■ 文件已修改
src/App.vue 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/directive/permission/hasPermi.ts 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/directive/permission/hasRole.ts 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/manifest.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/modules/user.ts 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/permission.ts 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/App.vue
@@ -17,10 +17,11 @@
    }, 5000);
    // 初始化推送服务
    initPushService();
    // initPushService();
  });
  // 初始化推送服务(uni-push 1.0)
  const initPushService = () => {
    return;
    // #ifdef APP-PLUS
    console.log("开始初始化推送服务(uni-push 1.0)");
    if (typeof plus !== "undefined" && plus.push) {
@@ -108,4 +109,4 @@
<style lang="scss">
  @import "uview-plus/index.scss";
  @import "@/static/scss/index.scss";
</style>
</style>
src/directive/permission/hasPermi.ts
@@ -1,30 +1,7 @@
/**
* v-hasPermi 操作权限处理
* Copyright (c) 2019 ruoyi
*/
import useUserStore from '@/store/modules/user'
import type { Directive } from "vue";
const vHasPermi: Directive = {
  mounted(el, binding, vnode) {
    const { value } = binding
    const all_permission = "*:*:*";
    const permissions = useUserStore().permissions
  mounted() {}
};
    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      const hasPermissions = permissions.some(permission => {
        return all_permission === permission || permissionFlag.includes(permission)
      })
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }
}
export default vHasPermi
export default vHasPermi;
src/directive/permission/hasRole.ts
@@ -1,30 +1,7 @@
/**
* v-hasRole 角色权限处理
* Copyright (c) 2019 ruoyi
*/
import useUserStore from '@/store/modules/user'
import type { Directive } from "vue";
const vHasRole: Directive = {
  mounted(el, binding, vnode) {
    const { value } = binding
    const super_admin = "admin";
    const roles = useUserStore().roles
  mounted() {}
};
    if (value && value instanceof Array && value.length > 0) {
      const roleFlag = value
      const hasRole = roles.some(role => {
        return super_admin === role || roleFlag.includes(role)
      })
      if (!hasRole) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置角色权限标签值`)
    }
  }
}
export default vHasRole;
export default vHasRole;
src/manifest.json
@@ -24,7 +24,7 @@
        "modules" : {
            "Camera" : {},
            "Barcode" : {},
            "Push" : {},
            // "Push" : {},
            "Maps" : {}
        },
        /* 应用发布信息 */
src/store/modules/user.ts
@@ -1,9 +1,7 @@
import {logout, getInfo, loginCheckFactory} from "@/api/login";
import { getRouters as getRoutersApi } from "@/api/menu";
import { logout, getInfo, loginCheckFactory } from "@/api/login";
import { getToken, setToken, removeToken } from "@/utils/auth";
import defAva from "@/static/images/profile.jpg";
import { defineStore } from "pinia";
import config from '@/config.js'
import config from "@/config.js";
export interface LoginForm {
  userName: string;
@@ -23,45 +21,45 @@
    currentLoginTime: "",
    roles: Array(),
    permissions: [],
    routers: [], // 路由权限数据
    routers: [],
  }),
  actions: {
    // 部门登录
    loginCheckFactory(userInfo: any) {
      const userName = userInfo.userName
      const password = userInfo.password
      const userName = userInfo.userName;
      const password = userInfo.password;
      return new Promise((resolve, reject) => {
        loginCheckFactory(userName, password).then((res: any) => {
          setToken(res.token)
          this.token = res.token
          resolve(null)
        }).catch((error: any) => {
          reject(error)
        })
      })
        loginCheckFactory(userName, password)
          .then((res: any) => {
            setToken(res.token);
            this.token = res.token;
            resolve(null);
          })
          .catch((error: any) => {
            reject(error);
          });
      });
    },
    // 获取用户信息
    getInfo() {
      return new Promise((resolve, reject) => {
        getInfo()
          .then((res: any) => {
            const user = res.user
            let avatar = user.avatar || ""
            avatar = config.baseUrl + '/profile/' + avatar
            if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
              this.roles = res.roles
              this.permissions = res.permissions
            const user = res.user;
            let avatar = user.avatar || "";
            avatar = config.baseUrl + "/profile/" + avatar;
            if (res.roles && res.roles.length > 0) {
              this.roles = res.roles;
              this.permissions = res.permissions;
            } else {
              this.roles = ['ROLE_DEFAULT']
              this.roles = ["ROLE_DEFAULT"];
            }
            this.id = user.userId
            this.name = user.userName
            this.avatar = avatar
            this.currentFactoryName = user.currentFactoryName
            this.nickName = user.nickName
            this.roleName = user.roles[0].roleName
            this.currentDeptId = user.tenantId
            this.currentLoginTime = this.getCurrentTime()
            this.id = user.userId;
            this.name = user.userName;
            this.avatar = avatar;
            this.currentFactoryName = user.currentFactoryName;
            this.nickName = user.nickName;
            this.roleName = user.roles[0].roleName;
            this.currentDeptId = user.tenantId;
            this.currentLoginTime = this.getCurrentTime();
            resolve(res);
          })
          .catch((error) => {
@@ -69,7 +67,6 @@
          });
      });
    },
    // 退出系统
    logOut() {
      return new Promise<null>((resolve, reject) => {
        logout()
@@ -90,26 +87,18 @@
    },
    getCurrentTime() {
      const now = new Date();
      const year = now.getFullYear();       // 获取年份
      const month = String(now.getMonth() + 1).padStart(2, '0');  // 月份从0开始,要+1,并补零
      const day = String(now.getDate()).padStart(2, '0');         // 日期补零
      const hours = String(now.getHours()).padStart(2, '0');      // 小时补零
      const minutes = String(now.getMinutes()).padStart(2, '0');  // 分钟补零
      const seconds = String(now.getSeconds()).padStart(2, '0');  // 秒数补零
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      const hours = String(now.getHours()).padStart(2, "0");
      const minutes = String(now.getMinutes()).padStart(2, "0");
      const seconds = String(now.getSeconds()).padStart(2, "0");
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    // 获取路由权限
    getRouters() {
      return new Promise((resolve, reject) => {
        getRoutersApi()
          .then((res: any) => {
            // 存储路由权限数据
            this.routers = res.data || [];
            resolve(res);
          })
          .catch((error) => {
            reject(error);
          });
      return new Promise((resolve) => {
        this.routers = [];
        resolve({ data: [] });
      });
    },
  },
src/utils/permission.ts
@@ -1,28 +1,10 @@
import useUserStore from '@/store/modules/user'
/**
 * 字符权限校验
 * @param {Array} value 校验值
 * @returns {Boolean}
 */
export function checkPermi(value:Array<string>) {
  if (value && value instanceof Array && value.length > 0) {
    const permissions:Array<string> = useUserStore().permissions
    const permissionDatas = value
    const all_permission = "*:*:*"
    const hasPermission = permissions.some(permission => {
      return all_permission === permission || permissionDatas.includes(permission)
    })
    if (!hasPermission) {
      return false
    }
    return true
  } else {
    console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
    return false
  }
  return true
}
/**
@@ -31,21 +13,5 @@
 * @returns {Boolean}
 */
export function checkRole(value:Array<string>) {
  if (value && value instanceof Array && value.length > 0) {
    const roles:Array<string> = useUserStore().roles
    const permissionRoles = value
    const super_admin = "admin"
    const hasRole = roles.some(role => {
      return super_admin === role || permissionRoles.includes(role)
    })
    if (!hasRole) {
      return false
    }
    return true
  } else {
    console.error(`need roles! Like checkRole="['admin','editor']"`)
    return false
  }
}
  return true
}