main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. let initApp = createApp(App);
  4. import router from './router'
  5. initApp.use(router);
  6. import store from './store'
  7. initApp.use(store);
  8. import ElementPlus from 'element-plus'
  9. import 'element-plus/dist/index.css'
  10. initApp.use(ElementPlus)
  11. // 如果您正在使用CDN引入,请删除下面一行。
  12. import * as ElementPlusIconsVue from '@element-plus/icons-vue'
  13. for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  14. initApp.component(key, component)
  15. }
  16. // 添加自定义方法,得到用户类型【1:游客;2:普通用户;3:管理员】
  17. const getUserType = () => {
  18. if (store.state.userInfo && store.state.userInfo.id != null) {
  19. // 得到用户id
  20. let userId = store.state.userInfo.id;
  21. // 得到角色ids
  22. let roleIds = store.state.userInfo.roleId;
  23. // 得到默认管理员角色id(roleId,在Oauth中配置)
  24. let adminRoleId = webConfig.defaultAccount.adminRoleId;
  25. if (!store.state.userInfo || !userId || !roleIds) {
  26. // 游客
  27. return 1;
  28. } else if (roleIds.split(",").includes(adminRoleId)) {
  29. // 管理员
  30. return 3;
  31. } else {
  32. // 普通用户
  33. return 2;
  34. }
  35. } else {
  36. // 游客
  37. return 1;
  38. }
  39. };
  40. initApp.config.globalProperties.$getUserType = getUserType;
  41. // 剪切板
  42. import useClipboard from 'vue-clipboard3'
  43. initApp.config.globalProperties.$copyText = function (text) {
  44. try {
  45. useClipboard().toClipboard(text);
  46. // this.$message({ message: '已复制到剪切板:' + text, type: 'success' })
  47. this.$message({ message: '复制成功', type: 'success' })
  48. } catch (e) { }
  49. }
  50. initApp.mount('#app');