main.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // console.log("=====userInfo==="+JSON.stringify(store.state.userInfo));
  19. if (store.state.userInfo && store.state.userInfo.id != null) {
  20. // 得到用户id
  21. let userId = store.state.userInfo.id;
  22. // 得到角色ids
  23. let roleIds = store.state.userInfo.roleId;
  24. // 得到默认管理员角色id(roleId,在Oauth中配置)
  25. let adminRoleId = webConfig.defaultAccount.adminRoleId;
  26. if (!store.state.userInfo || !userId || !roleIds) {
  27. // 游客
  28. return 1;
  29. } else if (roleIds.split(",").includes(adminRoleId)) {
  30. // 管理员
  31. return 3;
  32. } else {
  33. // 普通用户
  34. return 2;
  35. }
  36. } else {
  37. // 游客
  38. return 1;
  39. }
  40. };
  41. initApp.config.globalProperties.$getUserType = getUserType;
  42. // 剪切板
  43. import useClipboard from 'vue-clipboard3'
  44. initApp.config.globalProperties.$copyText = function (text) {
  45. try {
  46. useClipboard().toClipboard(text);
  47. // this.$message({ message: '已复制到剪切板:' + text, type: 'success' })
  48. this.$message({ message: '复制成功', type: 'success' })
  49. } catch (e) { }
  50. }
  51. initApp.mount('#app');