ljr-cli 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/lib/demo1.js +39 -0
  2. package/lib/demo2.js +87 -0
  3. package/lib/index.js +220 -14
  4. package/lib/templates/flutter//346/210/221/346/230/257flutter.txt +0 -0
  5. package/lib/templates/java//346/210/221/346/230/257java.txt +0 -0
  6. package/lib/templates/monorepo//346/210/221/346/230/257monorepo.txt +0 -0
  7. package/lib/templates/mysql//346/210/221/346/230/257mysql.txt +0 -0
  8. package/lib/templates/node//346/210/221/346/230/257node.txt +0 -0
  9. package/lib/templates/qiankun//346/210/221/346/230/257qiankun.txt +0 -0
  10. package/lib/templates/react//346/210/221/346/230/257react.txt +0 -0
  11. package/lib/templates/uni-app//346/210/221/346/230/257uni-app.txt +0 -0
  12. package/lib/templates/vue2.7.16/.browserslistrc +3 -0
  13. package/lib/templates/vue2.7.16/.env +4 -0
  14. package/lib/templates/vue2.7.16/.env.development +7 -0
  15. package/lib/templates/vue2.7.16/.env.production +7 -0
  16. package/lib/templates/vue2.7.16/.eslintignore +3 -0
  17. package/lib/templates/vue2.7.16/.eslintrc.js +21 -0
  18. package/lib/templates/vue2.7.16/.prettierrc.js +11 -0
  19. package/lib/templates/vue2.7.16/.vscode/settings.json +10 -0
  20. package/lib/templates/vue2.7.16/README.md +71 -0
  21. package/lib/templates/vue2.7.16/babel.config.js +3 -0
  22. package/lib/templates/vue2.7.16/jsconfig.json +19 -0
  23. package/lib/templates/vue2.7.16/package.json +41 -0
  24. package/lib/templates/vue2.7.16/pnpm-lock.yaml +8171 -0
  25. package/lib/templates/vue2.7.16/public/favicon.svg +14 -0
  26. package/lib/templates/vue2.7.16/public/index.html +20 -0
  27. package/lib/templates/vue2.7.16/src/App.vue +14 -0
  28. package/lib/templates/vue2.7.16/src/api/interface/index.js +6 -0
  29. package/lib/templates/vue2.7.16/src/api/request.js +121 -0
  30. package/lib/templates/vue2.7.16/src/api/server/index.js +6 -0
  31. package/lib/templates/vue2.7.16/src/assets/logo.png +0 -0
  32. package/lib/templates/vue2.7.16/src/components/README.md +5 -0
  33. package/lib/templates/vue2.7.16/src/components/baseInfo/index.vue +29 -0
  34. package/lib/templates/vue2.7.16/src/components/baseInfo/item.vue +64 -0
  35. package/lib/templates/vue2.7.16/src/components/index.js +14 -0
  36. package/lib/templates/vue2.7.16/src/components/layout/left-menu-and-top-info.vue +121 -0
  37. package/lib/templates/vue2.7.16/src/components/pagination/index.vue +52 -0
  38. package/lib/templates/vue2.7.16/src/css/coverage-style.css +6 -0
  39. package/lib/templates/vue2.7.16/src/directive/index.js +16 -0
  40. package/lib/templates/vue2.7.16/src/directive/input-number.js +18 -0
  41. package/lib/templates/vue2.7.16/src/directive/permission.js +52 -0
  42. package/lib/templates/vue2.7.16/src/directive/re-click.js +12 -0
  43. package/lib/templates/vue2.7.16/src/global-config.js +12 -0
  44. package/lib/templates/vue2.7.16/src/main.js +79 -0
  45. package/lib/templates/vue2.7.16/src/prototype/README.md +1 -0
  46. package/lib/templates/vue2.7.16/src/prototype/el-dialog.js +127 -0
  47. package/lib/templates/vue2.7.16/src/prototype/index.js +53 -0
  48. package/lib/templates/vue2.7.16/src/router/index.js +257 -0
  49. package/lib/templates/vue2.7.16/src/store/index.js +50 -0
  50. package/lib/templates/vue2.7.16/src/store/modules/dd.js +128 -0
  51. package/lib/templates/vue2.7.16/src/store/modules/permissions.js +24 -0
  52. package/lib/templates/vue2.7.16/src/views/404.vue +7 -0
  53. package/lib/templates/vue2.7.16/src/views/Pitfalls//345/206/205/345/255/230/346/272/242/345/207/272/index.vue +56 -0
  54. package/lib/templates/vue2.7.16/src/views/Pitfalls//345/206/205/345/255/230/346/272/242/345/207/272//351/200/240/346/210/220vue2/345/206/205/345/255/230/346/272/242/345/207/272/347/232/204/345/257/271/350/261/241.js +33518 -0
  55. package/lib/templates/vue2.7.16/src/views/about.vue +5 -0
  56. package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200store/346/225/260/346/215/256/345/255/227/345/205/270/index.vue +85 -0
  57. package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200/345/274/271/347/252/227/ce.vue +42 -0
  58. package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200/345/274/271/347/252/227/index.vue +24 -0
  59. package/lib/templates/vue2.7.16/src/views/demo//345/205/250/345/261/200/346/214/207/344/273/244/index.vue +78 -0
  60. package/lib/templates/vue2.7.16/src/views/demo//350/257/267/346/261/202/347/244/272/344/276/213/index.vue +51 -0
  61. package/lib/templates/vue2.7.16/src/views/home.vue +3 -0
  62. package/lib/templates/vue2.7.16/src/views/login.vue +67 -0
  63. package/lib/templates/vue2.7.16/src/views/template/base-info.vue +29 -0
  64. package/lib/templates/vue2.7.16/src/views/template/base-info2.vue +56 -0
  65. package/lib/templates/vue2.7.16/src/views/template/list/ce.vue +58 -0
  66. package/lib/templates/vue2.7.16/src/views/template/list/index.vue +111 -0
  67. package/lib/templates/vue2.7.16/src/views/template/list/search.vue +60 -0
  68. package/lib/templates/vue2.7.16/vue.config.js +26 -0
  69. package/lib/templates/vue3.5.25-2025.12.4/.editorconfig +8 -0
  70. package/lib/templates/vue3.5.25-2025.12.4/.gitattributes +1 -0
  71. package/lib/templates/vue3.5.25-2025.12.4/.prettierrc.json +11 -0
  72. package/lib/templates/vue3.5.25-2025.12.4/.vscode/extensions.json +8 -0
  73. package/lib/templates/vue3.5.25-2025.12.4/.vscode/settings.json +13 -0
  74. package/lib/templates/vue3.5.25-2025.12.4/README.md +93 -0
  75. package/lib/templates/vue3.5.25-2025.12.4/auto-imports.d.ts +78 -0
  76. package/lib/templates/vue3.5.25-2025.12.4/components.d.ts +28 -0
  77. package/lib/templates/vue3.5.25-2025.12.4/env.d.ts +1 -0
  78. package/lib/templates/vue3.5.25-2025.12.4/eslint.config.ts +32 -0
  79. package/lib/templates/vue3.5.25-2025.12.4/index.html +13 -0
  80. package/lib/templates/vue3.5.25-2025.12.4/package.json +47 -0
  81. package/lib/templates/vue3.5.25-2025.12.4/pnpm-lock.yaml +3515 -0
  82. package/lib/templates/vue3.5.25-2025.12.4/public/favicon.svg +14 -0
  83. package/lib/templates/vue3.5.25-2025.12.4/src/App.vue +12 -0
  84. package/lib/templates/vue3.5.25-2025.12.4/src/assets/vue.svg +1 -0
  85. package/lib/templates/vue3.5.25-2025.12.4/src/boot/index.ts +14 -0
  86. package/lib/templates/vue3.5.25-2025.12.4/src/boot/pinia.ts +10 -0
  87. package/lib/templates/vue3.5.25-2025.12.4/src/boot/router.ts +10 -0
  88. package/lib/templates/vue3.5.25-2025.12.4/src/boot/style.ts +9 -0
  89. package/lib/templates/vue3.5.25-2025.12.4/src/css/coverage-style.css +6 -0
  90. package/lib/templates/vue3.5.25-2025.12.4/src/directive/index.js +8 -0
  91. package/lib/templates/vue3.5.25-2025.12.4/src/directive/rememberScrollPosition.ts +17 -0
  92. package/lib/templates/vue3.5.25-2025.12.4/src/main.ts +7 -0
  93. package/lib/templates/vue3.5.25-2025.12.4/src/router/index.ts +20 -0
  94. package/lib/templates/vue3.5.25-2025.12.4/src/stores/counter.ts +12 -0
  95. package/lib/templates/vue3.5.25-2025.12.4/src/views/AboutView.vue +3 -0
  96. package/lib/templates/vue3.5.25-2025.12.4/src/views/HomeView.vue +14 -0
  97. package/lib/templates/vue3.5.25-2025.12.4/tsconfig.app.json +12 -0
  98. package/lib/templates/vue3.5.25-2025.12.4/tsconfig.json +11 -0
  99. package/lib/templates/vue3.5.25-2025.12.4/tsconfig.node.json +19 -0
  100. package/lib/templates/vue3.5.25-2025.12.4/vite.config.ts +31 -0
  101. package/lib/templates/wx-miniapp//346/210/221/346/230/257wx-miniapp.txt +0 -0
  102. package/package.json +16 -3
@@ -0,0 +1,79 @@
1
+ import Vue from "vue"
2
+ import App from "./App.vue"
3
+ import router from "./router"
4
+ import store from "./store"
5
+
6
+ import "l-global/css/index.css"
7
+ import "./css/coverage-style.css"
8
+
9
+ // 引入 ElementUI
10
+ import ElementUI from "element-ui"
11
+ import "element-ui/lib/theme-chalk/index.css"
12
+ Vue.use(ElementUI, { size: "small" })
13
+
14
+ // 引入原型扩展
15
+ import prototype from "@/prototype/index.js"
16
+ Vue.use(prototype)
17
+
18
+ // 引入指令
19
+ import directive from "@/directive/index.js"
20
+ Vue.use(directive)
21
+
22
+ // 引入全局组件
23
+ import "@/components/index.js"
24
+
25
+ Vue.config.productionTip = false
26
+
27
+ import { mapGetters } from "vuex"
28
+
29
+ new Vue({
30
+ router,
31
+ store,
32
+ computed: {
33
+ ...mapGetters(["dd"]),
34
+ },
35
+ render: (h) => h(App),
36
+ /** 这里是因为store的方法没有返回值,所以挂载到全局上 */
37
+ methods: {
38
+ /** 数据字典编码转换名称
39
+ * @param { Object } obj 对象类型
40
+ * @returns { String } 返回值,不存在或者不是对象格式返回空串
41
+ * @example
42
+ * $root.ddCodeToName({ sex: "1" })
43
+ */
44
+ ddCodeToName(obj) {
45
+ // 不存在直接返回空串
46
+ if (!obj) {
47
+ console.error("数据字典编码转换名称:参数为空,返回空字符串")
48
+ return ""
49
+ }
50
+
51
+ // 如果不是对象格式,返回空串
52
+ if (Object.prototype.toString.call(obj) !== "[object Object]") {
53
+ console.error(`ddCodeToName方法需要对象格式! 像 ddCodeToName({ sex: "1" })`)
54
+ return ""
55
+ }
56
+
57
+ // 如果是空对象,返回空串
58
+ if (!Object.keys(obj).length) {
59
+ console.error(`ddCodeToName方法需要对象格式! 像 ddCodeToName({ sex: "1" }),不能为空对象`)
60
+ return ""
61
+ }
62
+
63
+ const ddKey = Object.keys(obj)[0] // 数据字典的key
64
+ const dd = this.$root.dd?.[ddKey] || null
65
+ if (dd?.length) {
66
+ const currentDD = dd.filter((f) => f.value === obj[ddKey])[0] || null
67
+ if (currentDD) {
68
+ return currentDD.label
69
+ }
70
+ if (!currentDD) {
71
+ return obj[ddKey]
72
+ }
73
+ }
74
+ if (!dd) {
75
+ return obj[ddKey]
76
+ }
77
+ },
78
+ },
79
+ }).$mount("#app")
@@ -0,0 +1 @@
1
+ # 此文件夹是放一些挂载到原型上的
@@ -0,0 +1,127 @@
1
+ const dialogMixin = {
2
+ props: {
3
+ title: {
4
+ type: [String],
5
+ default: "",
6
+ },
7
+ width: {
8
+ type: [String],
9
+ default: "50%",
10
+ },
11
+ fullscreen: {
12
+ type: [Boolean],
13
+ default: false,
14
+ },
15
+ top: {
16
+ type: [String],
17
+ default: "15vh",
18
+ },
19
+ modal: {
20
+ type: [Boolean],
21
+ default: true,
22
+ },
23
+ modalAppendToBody: {
24
+ type: [Boolean],
25
+ default: true,
26
+ },
27
+ appendToBody: {
28
+ type: [Boolean],
29
+ default: true,
30
+ },
31
+ lockScroll: {
32
+ type: [Boolean],
33
+ default: true,
34
+ },
35
+ customClass: {
36
+ type: [String],
37
+ default: "",
38
+ },
39
+ closeOnClickModal: {
40
+ type: [Boolean],
41
+ default: true,
42
+ },
43
+ closeOnPressEscape: {
44
+ type: [Boolean],
45
+ default: true,
46
+ },
47
+ showClose: {
48
+ type: [Boolean],
49
+ default: true,
50
+ },
51
+ beforeClose: {
52
+ type: [Function],
53
+ },
54
+ center: {
55
+ type: [Boolean],
56
+ default: false,
57
+ },
58
+ destroyOnClose: {
59
+ type: [Boolean],
60
+ default: false,
61
+ },
62
+ on: {
63
+ type: Object,
64
+ default: () => {},
65
+ },
66
+ },
67
+ data() {
68
+ return {
69
+ visible: false,
70
+ }
71
+ },
72
+ watch: {
73
+ visible(value) {
74
+ // 动画结束后销毁实例
75
+ if (value === false) {
76
+ setTimeout(() => {
77
+ this.$destroy()
78
+ if (this?.$el?.parentNode) {
79
+ this.$el.parentNode.removeChild(this.$el)
80
+ }
81
+ }, 400)
82
+ }
83
+ },
84
+ },
85
+ mounted() {
86
+ document.body.appendChild(this.$el)
87
+ this.visible = true
88
+ },
89
+ methods: {
90
+ // 关闭对话框
91
+ close(refresh) {
92
+ this.visible = false
93
+ if (refresh) {
94
+ this?.on?.refresh(true) // 刷新
95
+ }
96
+ },
97
+ },
98
+ }
99
+
100
+ export default {
101
+ install(Vue, config = {}) {
102
+ Vue.prototype[`$${config.prefix}Dialog`] = (component, props) => {
103
+ component.default && (component = component.default)
104
+ const mixins = component.mixins || []
105
+ mixins.push(dialogMixin) // 实现自动打开,动态了混入生命周期函数和销毁操作
106
+ component.mixins = mixins
107
+ const Dialog = Vue.extend(component)
108
+ const dialog = new Dialog({
109
+ propsData: props || {},
110
+ })
111
+ dialog.$mount()
112
+ }
113
+ },
114
+ }
115
+
116
+ // 使用示例
117
+ // 1.在需要调用的地方调用
118
+ // ce() {
119
+ // this.$LDialog(require("./ce.vue"), {
120
+ // title: "创建编辑",
121
+ // on: {
122
+ // refresh: () => {
123
+ // console.log("刷新方法")
124
+ // }
125
+ // }
126
+ // })
127
+ // }
@@ -0,0 +1,53 @@
1
+ // 全局配置
2
+ import globalConfig from "@/global-config.js"
3
+
4
+ import request from "@/api/request.js"
5
+
6
+ // 要挂载到原型的弹窗组件
7
+ import elDialog from "./el-dialog.js"
8
+
9
+ export default {
10
+ install(Vue) {
11
+ Vue.use(elDialog, globalConfig)
12
+ // 全局事件总线
13
+ Vue.prototype.$eventBus = new Vue()
14
+ // 挂载请求方法到原型
15
+ Vue.prototype.$api = request
16
+ // 原型的请求使用示例
17
+
18
+ // this.$api
19
+ // .service({
20
+ // method: "get",
21
+ // url,
22
+ // headers: {
23
+ // ...(header || {}),
24
+ // },
25
+ // responseType,
26
+ // params,
27
+ // })
28
+ // .then((res) => {
29
+ // console.log("res=====>", res)
30
+ // })
31
+ // .catch((err) => {
32
+ // console.log("err=====>", err)
33
+ // })
34
+ // .finally((err) => {
35
+ // console.log("err=====>", err)
36
+ // })
37
+
38
+ // // get示例
39
+ // this.$api.get(this.remoteUrl, {}).then((res) => {
40
+ // console.log("res=====>", res)
41
+ // })
42
+
43
+ // // post示例
44
+ // this.$api.post(url, params).then((res) => {
45
+ // console.log("res=====>", res)
46
+ // })
47
+
48
+ // // postFormData示例
49
+ // this.$api.postFormData(url, params).then((res) => {
50
+ // console.log("res=====>", res)
51
+ // })
52
+ },
53
+ }
@@ -0,0 +1,257 @@
1
+ import Vue from "vue"
2
+ import VueRouter from "vue-router"
3
+ import store from "@/store/index.js"
4
+ // 左侧菜单和顶部信息布局组件
5
+ import LeftMenuAndTopInfo from "@/components/layout/left-menu-and-top-info.vue"
6
+
7
+ Vue.use(VueRouter)
8
+ const routes = [
9
+ {
10
+ // WARNING: 最终的生成的路径是父级+子级的路径,注意子级不要加/,否则视为绝对路径
11
+ path: "/",
12
+ component: LeftMenuAndTopInfo,
13
+ children: [
14
+ {
15
+ path: "",
16
+ name: "home",
17
+ component: () => import("@/views/home.vue"),
18
+ meta: {
19
+ /** 标题 */
20
+ title: "主页",
21
+ /** 菜单图标 */
22
+ titleIcon: "el-icon-s-home",
23
+ /** 是否菜单 */
24
+ isMenu: true,
25
+ },
26
+ },
27
+ ],
28
+ },
29
+ {
30
+ path: "/demo",
31
+ component: LeftMenuAndTopInfo,
32
+ meta: {
33
+ title: "案例",
34
+ titleIcon: "el-icon-star-on",
35
+ isMenu: true,
36
+ },
37
+ children: [
38
+ {
39
+ path: "global-dialog",
40
+ name: "globalDialog",
41
+ component: () => import("@/views/demo/全局弹窗/index.vue"),
42
+ meta: {
43
+ title: "全局弹窗",
44
+ titleIcon: "el-icon-postcard",
45
+ isMenu: true,
46
+ },
47
+ },
48
+ {
49
+ path: "global-store-dd",
50
+ name: "globalStoreDD",
51
+ component: () => import("@/views/demo/全局store数据字典/index.vue"),
52
+ meta: {
53
+ title: "全局store数据字典",
54
+ titleIcon: "el-icon-s-data",
55
+ isMenu: true,
56
+ },
57
+ },
58
+ {
59
+ path: "global-directive",
60
+ name: "globalDirective",
61
+ component: () => import("@/views/demo/全局指令/index.vue"),
62
+ meta: {
63
+ title: "全局指令",
64
+ titleIcon: "el-icon-s-grid",
65
+ isMenu: true,
66
+ },
67
+ },
68
+ {
69
+ path: "api-demo",
70
+ name: "apiDemo",
71
+ component: () => import("@/views/demo/请求示例/index.vue"),
72
+ meta: {
73
+ title: "请求示例",
74
+ titleIcon: "el-icon-s-grid",
75
+ isMenu: true,
76
+ },
77
+ },
78
+ ],
79
+ },
80
+ {
81
+ path: "/template",
82
+ component: LeftMenuAndTopInfo,
83
+ meta: {
84
+ title: "模版",
85
+ titleIcon: "el-icon-star-on",
86
+ isMenu: true,
87
+ },
88
+ children: [
89
+ {
90
+ path: "list",
91
+ name: "list",
92
+ component: () => import("@/views/template/list/index.vue"),
93
+ meta: {
94
+ title: "列表",
95
+ titleIcon: "el-icon-document",
96
+ isMenu: true,
97
+ },
98
+ },
99
+ {
100
+ path: "base-info",
101
+ name: "baseInfo",
102
+ component: () => import("@/views/template/base-info.vue"),
103
+ meta: {
104
+ title: "基础信息布局",
105
+ titleIcon: "el-icon-document",
106
+ isMenu: true,
107
+ needPadding: false,
108
+ },
109
+ },
110
+ {
111
+ path: "base-info2",
112
+ name: "baseInfo2",
113
+ component: () => import("@/views/template/base-info2.vue"),
114
+ meta: {
115
+ title: "基础信息布局2",
116
+ titleIcon: "el-icon-coffee-cup",
117
+ isMenu: true,
118
+ needPadding: false,
119
+ },
120
+ },
121
+ ],
122
+ },
123
+ {
124
+ path: "/Pitfalls",
125
+ component: LeftMenuAndTopInfo,
126
+ meta: {
127
+ title: "遇到的坑",
128
+ titleIcon: "el-icon-star-on",
129
+ isMenu: true,
130
+ },
131
+ children: [
132
+ {
133
+ path: "memory-overflow",
134
+ name: "memoryOverflow",
135
+ component: () => import("@/views/Pitfalls/内存溢出/index.vue"),
136
+ meta: {
137
+ title: "内存溢出",
138
+ titleIcon: "el-icon-postcard",
139
+ isMenu: true,
140
+ },
141
+ },
142
+ ],
143
+ },
144
+ {
145
+ path: "/login",
146
+ name: "login",
147
+ component: () => import("@/views/login.vue"),
148
+ meta: {
149
+ title: "登录页",
150
+ titleIcon: "el-icon-s-custom",
151
+ isMenu: true,
152
+ },
153
+ },
154
+ {
155
+ path: "/",
156
+ component: LeftMenuAndTopInfo,
157
+ children: [
158
+ {
159
+ path: "about",
160
+ name: "about",
161
+ component: () => import("@/views/about.vue"),
162
+ meta: {
163
+ title: "关于页",
164
+ titleIcon: "el-icon-s-comment",
165
+ isMenu: true,
166
+ },
167
+ },
168
+ {
169
+ path: "404",
170
+ name: "404",
171
+ meta: {
172
+ title: "404",
173
+ titleIcon: "el-icon-menu",
174
+ isMenu: true,
175
+ },
176
+ component: () => import("@/views/404.vue"),
177
+ },
178
+ ],
179
+ },
180
+ {
181
+ path: "*",
182
+ redirect: "/404", // 重定向到404页面
183
+ },
184
+ ]
185
+
186
+ const router = new VueRouter({
187
+ mode: "hash", // hash | history
188
+ base: process.env.BASE_URL,
189
+ routes,
190
+ })
191
+
192
+ // 全局路由守卫
193
+ router.beforeEach((to, from, next) => {
194
+ // 需要登录 并且 登录状态为false 并且 不是登录页面
195
+ if (store.state.needLogin && !store.state.loginStatus && to.name !== "login") {
196
+ if (from.name !== "login") {
197
+ router.push({ name: "login" })
198
+ }
199
+ next(false)
200
+ return
201
+ }
202
+ next()
203
+ })
204
+
205
+ /** 获取菜单,仅支持两级 */
206
+ export const getMenu = function () {
207
+ const menu = []
208
+ router.options.routes.forEach((e1) => {
209
+ // 如果父级有配置isMenu,并且没有子级,则作为一级菜单
210
+ if (!e1.children?.length && e1.meta?.isMenu) {
211
+ menu.push({
212
+ fullPath: e1.path,
213
+ title: e1.meta?.title,
214
+ titleIcon: e1.meta?.titleIcon,
215
+ })
216
+ }
217
+
218
+ // 循环子级,如果子级有配置isMenu,则将父级作为一级菜单,自己作为二级菜单
219
+ if (e1.children?.length) {
220
+ // 子级菜单
221
+ const childrenMenu = e1.children.filter((f) => f.meta?.isMenu)
222
+ if (childrenMenu.length) {
223
+ // 如果第一级有配置isMenu
224
+ if (e1.meta?.isMenu) {
225
+ const currentFather = {
226
+ fullPath: e1.path,
227
+ title: e1.meta?.title,
228
+ titleIcon: e1.meta?.titleIcon,
229
+ children: [],
230
+ }
231
+ childrenMenu.forEach((e2) => {
232
+ currentFather.children.push({
233
+ fullPath: e1.path + "/" + e2.path,
234
+ title: e2.meta?.title,
235
+ titleIcon: e2.meta?.titleIcon,
236
+ })
237
+ })
238
+ menu.push(currentFather)
239
+ }
240
+
241
+ // 如果第一级没有配置isMenu,则将第二级菜单作为父级菜单
242
+ if (!e1.meta?.isMenu) {
243
+ childrenMenu.forEach((e2) => {
244
+ menu.push({
245
+ fullPath: e1.path + e2.path,
246
+ title: e2.meta?.title,
247
+ titleIcon: e2.meta?.titleIcon,
248
+ })
249
+ })
250
+ }
251
+ }
252
+ }
253
+ })
254
+ return menu
255
+ }
256
+
257
+ export default router
@@ -0,0 +1,50 @@
1
+ import Vue from "vue"
2
+ import Vuex from "vuex"
3
+ import VuexPersistence from "vuex-persist"
4
+ import dd from "./modules/dd.js"
5
+ import permissions from "./modules/permissions.js"
6
+
7
+ Vue.use(Vuex)
8
+
9
+ const vuexLocal = new VuexPersistence({
10
+ storage: window.localStorage,
11
+ })
12
+
13
+ export default new Vuex.Store({
14
+ state: {
15
+ /** 是否需要登录 */
16
+ needLogin: false,
17
+
18
+ /** 登录状态 */
19
+ loginStatus: false,
20
+ },
21
+ /** 对store进行派生 */
22
+ getters: {
23
+ dd: (state) => state.dd.all,
24
+ permissions: (state) => state.permissions.permissions,
25
+ },
26
+ /** 同步函数,也是唯一修改state的方法,可以直接通过this.$store.commit() 触发 */
27
+ mutations: {
28
+ /** 改变登录状态,这里仅演示,不调用任何接口直接改变状态 */
29
+ changeLoginStatus(state) {
30
+ state.loginStatus = !state.loginStatus
31
+ },
32
+ /** 改变是否需要登录 */
33
+ changeNeedLogin(state) {
34
+ state.needLogin = !state.needLogin
35
+ },
36
+ },
37
+ /** 异步函数,可以通过 store.dispatch('asyncActionsFn') */
38
+ actions: {
39
+ asyncActionsFn() {
40
+ console.log("我是异步actions方法=====>")
41
+ },
42
+ },
43
+ /** 模块 */
44
+ modules: {
45
+ dd,
46
+ permissions,
47
+ },
48
+ /** 插件 */
49
+ plugins: [vuexLocal.plugin],
50
+ })
@@ -0,0 +1,128 @@
1
+ import { cloneDeep } from "lodash"
2
+
3
+ const dd = {
4
+ state: {
5
+ // 为了不一定那么多字段,所以这里定义一个对象
6
+ all: {
7
+ // sex: null, // 这里不需要定义也可以
8
+ // citys: null // 这里不需要定义也可以
9
+ },
10
+ },
11
+ // 同步执行,专注于修改State,理论上是修改State的唯一途径
12
+ // 调用 this.$store.commit('SET_DD')
13
+ mutations: {
14
+ /** 设置字典 */
15
+ SET_DD: (state, { code, data }) => {
16
+ const temp = cloneDeep(state.all)
17
+ temp[code] = data
18
+ state.all = temp
19
+ },
20
+ /** 清空字典 */
21
+ CLEAR_DD: (state) => {
22
+ state.all = {}
23
+ },
24
+ },
25
+ // 异步,但不能直接操作State,一般用来写业务代码、异步请求
26
+ // 调用 this.$store.dispatch('GET_DD')
27
+ actions: {
28
+ /** 获取字典 */
29
+ getDD({ commit, state }, code) {
30
+ if (state.all[code] && state.all[code] !== null) {
31
+ return
32
+ }
33
+ // 先随便设置一个 null 以外的值,以免重复请求
34
+ commit("SET_DD", { code, data: [] })
35
+ if (code === "sex") {
36
+ commit("SET_DD", {
37
+ code,
38
+ data: [
39
+ { label: "男", value: "1" },
40
+ { label: "女", value: "0" },
41
+ ],
42
+ })
43
+ }
44
+ if (code === "citys") {
45
+ commit("SET_DD", {
46
+ code,
47
+ data: [
48
+ { label: "北京", value: "1" },
49
+ { label: "上海", value: "2" },
50
+ { label: "广州", value: "3" },
51
+ { label: "深圳", value: "4" },
52
+ { label: "厦门", value: "5" },
53
+ ],
54
+ })
55
+ }
56
+ },
57
+ },
58
+ }
59
+
60
+ // 使用说明:
61
+ // 1.使用的页面需要调用一下getDD方法,如果数据字典的code !== null,则不会再次请求,为了优化性能不会一开始就全部存到store里
62
+ // this.$store.dispatch("getDD", "sex")
63
+ // this.$store.dispatch("getDD", "citys")
64
+
65
+ // 2.然后在真正需要使用数据字典的地方 $store.getters.dd.*** ***表示字典的code
66
+ // 例子:
67
+ // <el-select v-model="activeCity" placeholder="请选择">
68
+ // <el-option v-for="item in $store.getters.dd.citys" :key="item.value" :label="item.label" :value="item.value">
69
+ // </el-option>
70
+ // </el-select>
71
+
72
+ // 如果需要把code转换成name,可以使用下面的方法:
73
+
74
+ // 1.在main.js里添加
75
+ // import { mapGetters } from "vuex"
76
+
77
+ // 2.在new Vue() 里添加计算属性和全局字典转换name方法
78
+ // new Vue({
79
+ // el: "#app",
80
+ // computed: {
81
+ // ...mapGetters(["dd"]),
82
+ // },
83
+ // methods: {
84
+ // /** 数据字典编码转换名称
85
+ // * @param { Object } obj 对象类型
86
+ // * @returns { String } 返回值,不存在或者不是对象格式返回空串
87
+ // * @example
88
+ // * $root.ddCodeToName({ sex: "1" })
89
+ // */
90
+ // ddCodeToName(obj) {
91
+ // // 不存在直接返回空串
92
+ // if (!obj) {
93
+ // console.error("数据字典编码转换名称:参数为空,返回空字符串")
94
+ // return ""
95
+ // }
96
+
97
+ // // 如果不是对象格式,返回空串
98
+ // if (Object.prototype.toString.call(obj) !== "[object Object]") {
99
+ // console.error(`ddCodeToName方法需要对象格式! 像 ddCodeToName({ sex: "1" })`)
100
+ // return ""
101
+ // }
102
+
103
+ // // 如果是空对象,返回空串
104
+ // if (!Object.keys(obj).length) {
105
+ // console.error(`ddCodeToName方法需要对象格式! 像 ddCodeToName({ sex: "1" }),不能为空对象`)
106
+ // return ""
107
+ // }
108
+
109
+ // const ddKey = Object.keys(obj)[0] // 数据字典的key
110
+ // const dd = this.$root.dd?.[ddKey] || null
111
+ // if (dd?.length) {
112
+ // const currentDD = dd.filter((f) => f.value === obj[ddKey])[0] || null
113
+ // if (currentDD) {
114
+ // return currentDD.label
115
+ // }
116
+ // if (!currentDD) {
117
+ // return obj[ddKey]
118
+ // }
119
+ // }
120
+ // if (!dd) {
121
+ // return obj[ddKey]
122
+ // }
123
+ // },
124
+ // },
125
+ // render: (h) => h(App),
126
+ // })
127
+
128
+ export default dd