jobsys-explore 4.6.21 → 4.7.0

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 (180) hide show
  1. package/.eslintignore +3 -3
  2. package/CHANGELOG.md +542 -542
  3. package/README.md +41 -41
  4. package/TODOs.md +8 -8
  5. package/business-components/survey/ExSurvey.jsx +193 -193
  6. package/business-components/survey/index.js +5 -5
  7. package/business-components/survey/index.less +36 -36
  8. package/components/button/ExButton.jsx +120 -120
  9. package/components/button/index.js +4 -4
  10. package/components/button/index.less +7 -7
  11. package/components/decorator/ExDecorator.jsx +31 -31
  12. package/components/decorator/index.js +5 -5
  13. package/components/decorator/index.less +76 -76
  14. package/components/form/ExAddress.jsx +195 -195
  15. package/components/form/ExCascader.jsx +171 -171
  16. package/components/form/ExCheckbox.jsx +59 -59
  17. package/components/form/ExDate.jsx +143 -143
  18. package/components/form/ExDatetime.jsx +166 -166
  19. package/components/form/ExField.jsx +138 -138
  20. package/components/form/ExFieldUploader.jsx +50 -50
  21. package/components/form/ExForm.jsx +544 -544
  22. package/components/form/ExMatrixCheckbox.jsx +99 -99
  23. package/components/form/ExMatrixRadio.jsx +86 -86
  24. package/components/form/ExMatrixScale.jsx +97 -97
  25. package/components/form/ExNumber.jsx +51 -51
  26. package/components/form/ExRadio.jsx +58 -58
  27. package/components/form/ExRate.jsx +51 -51
  28. package/components/form/ExSelect.jsx +251 -251
  29. package/components/form/ExSlider.jsx +55 -55
  30. package/components/form/ExSwitch.jsx +51 -51
  31. package/components/form/ExTime.jsx +99 -99
  32. package/components/form/FormItem.jsx +307 -307
  33. package/components/form/PickerWrapper.jsx +120 -120
  34. package/components/form/index.js +46 -46
  35. package/components/form/index.less +178 -178
  36. package/components/form/utils.js +62 -62
  37. package/components/grid/ExGrid.jsx +53 -53
  38. package/components/grid/index.js +4 -4
  39. package/components/grid/index.less +2 -2
  40. package/components/index.js +12 -12
  41. package/components/pagination/ExPagination.jsx +457 -440
  42. package/components/pagination/index.js +5 -5
  43. package/components/pagination/index.less +3 -3
  44. package/components/provider/ExProvider.jsx +173 -173
  45. package/components/qrcode/ExQrcode.jsx +86 -86
  46. package/components/qrcode/index.js +5 -5
  47. package/components/qrcode/index.less +8 -8
  48. package/components/result/ExResult.jsx +122 -122
  49. package/components/result/index.js +5 -5
  50. package/components/result/index.less +59 -59
  51. package/components/search/ExSearch.jsx +370 -326
  52. package/components/search/components/Expand.jsx +77 -77
  53. package/components/search/components/Field.jsx +27 -27
  54. package/components/search/components/Quick.jsx +57 -57
  55. package/components/search/components/index.js +5 -5
  56. package/components/search/index.js +5 -5
  57. package/components/search/index.less +118 -118
  58. package/components/search/utils.js +30 -30
  59. package/components/sector/ExSector.jsx +52 -52
  60. package/components/sector/README.md +26 -26
  61. package/components/sector/index.js +5 -5
  62. package/components/sector/index.less +122 -122
  63. package/components/theme/ExTheme.jsx +10 -10
  64. package/components/theme/index.js +4 -4
  65. package/components/theme/index.less +98 -98
  66. package/components/uploader/ExUploader.jsx +293 -293
  67. package/components/uploader/index.js +5 -5
  68. package/components/utils.js +187 -187
  69. package/directives/auth.js +113 -113
  70. package/directives/index.js +4 -4
  71. package/dist/cipher-98df1050.cjs.map +1 -1
  72. package/dist/cipher-f2ed5ee6.js.map +1 -1
  73. package/dist/directives.cjs.map +1 -1
  74. package/dist/directives.js.map +1 -1
  75. package/dist/hooks.cjs.map +1 -1
  76. package/dist/hooks.js.map +1 -1
  77. package/dist/jobsys-explore.cjs +6 -6
  78. package/dist/jobsys-explore.cjs.map +1 -1
  79. package/dist/jobsys-explore.js +464 -407
  80. package/dist/jobsys-explore.js.map +1 -1
  81. package/docgen.config.js +15 -15
  82. package/docs/.vuepress/.cache/deps/_metadata.json +52 -52
  83. package/docs/.vuepress/.cache/deps/lodash-es.js +8442 -8442
  84. package/docs/.vuepress/.cache/deps/lodash-es.js.map +7 -7
  85. package/docs/.vuepress/.temp/internal/clientConfigs.js +17 -17
  86. package/docs/.vuepress/.temp/internal/pagesComponents.js +24 -24
  87. package/docs/.vuepress/.temp/internal/pagesData.js +22 -22
  88. package/docs/.vuepress/.temp/internal/pagesRoutes.js +12 -12
  89. package/docs/.vuepress/.temp/internal/themeData.js +1 -1
  90. package/docs/.vuepress/.temp/pages/components/decorator/ExDecorator.html.js +1 -1
  91. package/docs/.vuepress/.temp/pages/components/decorator/ExDecorator.html.vue +37 -37
  92. package/docs/.vuepress/.temp/pages/components/sector/ExSector.html.js +1 -1
  93. package/docs/.vuepress/.temp/pages/components/sector/ExSector.html.vue +71 -71
  94. package/docs/.vuepress/.temp/styles/index.scss +1 -1
  95. package/docs/.vuepress/config.js +61 -61
  96. package/docs/.vuepress/dist/404.html +33 -33
  97. package/docs/.vuepress/dist/assets/404.html-a0ce2184.js +1 -1
  98. package/docs/.vuepress/dist/assets/ExButton.html-ad283101.js +1 -1
  99. package/docs/.vuepress/dist/assets/ExDecorator.html-42d09114.js +1 -1
  100. package/docs/.vuepress/dist/assets/ExDecorator.html-c82c5fe8.js +1 -1
  101. package/docs/.vuepress/dist/assets/ExForm.html-9e3f8000.js +1 -1
  102. package/docs/.vuepress/dist/assets/ExProvider.html-78fdc6cd.js +1 -1
  103. package/docs/.vuepress/dist/assets/ExSearch.html-103f6f34.js +1 -1
  104. package/docs/.vuepress/dist/assets/ExSector.html-a1e24c3a.js +7 -7
  105. package/docs/.vuepress/dist/assets/ExSector.html-cff3fefd.js +1 -1
  106. package/docs/.vuepress/dist/assets/ExUploader.html-8310e424.js +1 -1
  107. package/docs/.vuepress/dist/assets/app-29fe8d1e.js +10 -10
  108. package/docs/.vuepress/dist/assets/hooks.html-90ccbc1a.js +1 -1
  109. package/docs/.vuepress/dist/assets/index.html-85b79c97.js +43 -43
  110. package/docs/.vuepress/dist/assets/style-46d7e227.css +1 -1
  111. package/docs/.vuepress/dist/components/button/ExButton.html +33 -33
  112. package/docs/.vuepress/dist/components/decorator/ExDecorator.html +33 -33
  113. package/docs/.vuepress/dist/components/form/ExForm.html +33 -33
  114. package/docs/.vuepress/dist/components/provider/ExProvider.html +33 -33
  115. package/docs/.vuepress/dist/components/search/ExSearch.html +33 -33
  116. package/docs/.vuepress/dist/components/sector/ExSector.html +39 -39
  117. package/docs/.vuepress/dist/components/uploader/ExUploader.html +33 -33
  118. package/docs/.vuepress/dist/hooks.html +33 -33
  119. package/docs/.vuepress/dist/index.html +75 -75
  120. package/docs/.vuepress/styles/index.scss +7 -7
  121. package/docs/components/decorator/ExDecorator.md +14 -14
  122. package/docs/components/sector/ExSector.md +43 -43
  123. package/docs/index.md +82 -82
  124. package/hooks/cipher.js +44 -44
  125. package/hooks/datetime.js +69 -69
  126. package/hooks/form.js +188 -188
  127. package/hooks/utils.js +282 -282
  128. package/index.html +17 -17
  129. package/package.json +1 -1
  130. package/playground/App.vue +191 -191
  131. package/playground/TestButton.vue +61 -61
  132. package/playground/TestCascader.vue +2442 -2442
  133. package/playground/TestDecorator.vue +14 -14
  134. package/playground/TestForm.vue +429 -429
  135. package/playground/TestFormItem.vue +110 -110
  136. package/playground/TestGrid.vue +22 -22
  137. package/playground/TestPagination.vue +1250 -1248
  138. package/playground/TestQrcode.vue +7 -7
  139. package/playground/TestResult.vue +12 -12
  140. package/playground/TestSearch.vue +115 -115
  141. package/playground/TestSector.vue +15 -15
  142. package/playground/TestSurvey.vue +27 -27
  143. package/playground/TestUploader.vue +14 -14
  144. package/playground/main.js +22 -22
  145. package/utils/style.js +13 -13
  146. package/vite.config.js +54 -54
  147. package/.changeset/blue-spiders-roll.md +0 -5
  148. package/.changeset/cyan-monkeys-draw.md +0 -5
  149. package/.changeset/dry-feet-float.md +0 -5
  150. package/.changeset/empty-mice-share.md +0 -5
  151. package/.changeset/famous-yaks-doubt.md +0 -5
  152. package/.changeset/five-fans-type.md +0 -5
  153. package/.changeset/funny-hats-drop.md +0 -5
  154. package/.changeset/khaki-cobras-bathe.md +0 -5
  155. package/.changeset/khaki-forks-shave.md +0 -5
  156. package/.changeset/lazy-yaks-crash.md +0 -5
  157. package/.changeset/light-cycles-flow.md +0 -5
  158. package/.changeset/loud-mirrors-explain.md +0 -5
  159. package/.changeset/lovely-balloons-protect.md +0 -5
  160. package/.changeset/mean-pens-travel.md +0 -5
  161. package/.changeset/moody-doors-grow.md +0 -5
  162. package/.changeset/moody-laws-change.md +0 -5
  163. package/.changeset/nasty-goats-joke.md +0 -5
  164. package/.changeset/odd-forks-drop.md +0 -5
  165. package/.changeset/olive-windows-suffer.md +0 -5
  166. package/.changeset/popular-carpets-jog.md +0 -5
  167. package/.changeset/popular-planets-play.md +0 -5
  168. package/.changeset/rare-gorillas-boil.md +0 -5
  169. package/.changeset/rare-moose-teach.md +0 -5
  170. package/.changeset/sharp-tools-hope.md +0 -5
  171. package/.changeset/slimy-sloths-refuse.md +0 -5
  172. package/.changeset/slow-boats-search.md +0 -5
  173. package/.changeset/small-experts-bake.md +0 -5
  174. package/.changeset/smooth-horses-tie.md +0 -5
  175. package/.changeset/tame-feet-reply.md +0 -5
  176. package/.changeset/tidy-items-reflect.md +0 -5
  177. package/.changeset/weak-chicken-admire.md +0 -5
  178. package/.changeset/weak-rockets-compare.md +0 -5
  179. package/.changeset/wild-glasses-bathe.md +0 -5
  180. package/.changeset/wise-ears-turn.md +0 -5
@@ -1,187 +1,187 @@
1
- import { cloneDeep, isFunction, isNumber, isString } from "lodash-es"
2
- import { watch } from "vue"
3
- import { useCache, useFetch } from "../hooks"
4
-
5
- /**
6
- * 通用 field props
7
- */
8
- export const defaultFieldProps = {
9
- /**
10
- * 输入框左侧文本
11
- */
12
- label: { type: String, default: "" },
13
-
14
- /**
15
- * 名称,作为提交表单时的标识符
16
- */
17
- name: { type: String, default: "" },
18
-
19
- /**
20
- * 输入框占位提示文字
21
- */
22
- placeholder: { type: String, default: "请填写" },
23
-
24
- /**
25
- * 提示文案
26
- */
27
- help: { type: [String, Function], default: "" },
28
-
29
- /**
30
- * 元素的append slot
31
- */
32
- append: { type: [String, Function], default: "" },
33
-
34
- /**
35
- * 是否禁用输入框
36
- */
37
- disabled: { type: Boolean, default: false },
38
-
39
- /**
40
- * 是否显示表单必填星号
41
- */
42
- required: { type: Boolean, default: false },
43
-
44
- /**
45
- * 是否展示右侧箭头并开启点击反馈
46
- */
47
- isLink: { type: Boolean, default: false },
48
-
49
- /**
50
- * 是否为只读状态,只读状态下无法输入内容
51
- */
52
- readonly: { type: Boolean, default: false },
53
-
54
- /**
55
- * 表单校验规则
56
- */
57
- rules: { type: Array, default: null },
58
-
59
- /**
60
- * 原生 [Field 配置](https://vant-contrib.gitee.io/vant/#/zh-CN/field)
61
- */
62
- fieldProps: { type: Object, default: () => ({}) },
63
-
64
- /**
65
- * 原生输入组件的 props
66
- */
67
- defaultProps: { type: Object, default: () => ({}) },
68
- }
69
-
70
- /**
71
- * 原生 Field 的 slots
72
- * 用于从组合组件中挑选
73
- */
74
- export const defaultFieldSlots = {
75
- label: () => null,
76
- input: () => null,
77
- "left-icon": () => null,
78
- "right-icon": () => null,
79
- button: () => null,
80
- "error-message": () => null,
81
- extra: () => null,
82
- }
83
-
84
- /**
85
- * 通用的 options props
86
- */
87
- export const defaultOptionsProps = {
88
- /**
89
- * 选项
90
- */
91
- options: { type: [Array, Function], default: () => [] },
92
-
93
- /**
94
- * 选项 url
95
- */
96
- url: { type: String, default: null },
97
-
98
- /**
99
- * 缓存url返回的数据
100
- */
101
- urlCache: { type: Boolean, default: true },
102
-
103
- /**
104
- * 选项获取后的回调
105
- */
106
- afterFetched: { type: Function, default: null },
107
- }
108
-
109
- /**
110
- * Prepare options for select
111
- *
112
- * @param options
113
- * @return {Array}
114
- */
115
- export const prepareOptions = (options) => {
116
- options = isFunction(options) ? options() : options
117
- options = cloneDeep(options).map((op) => {
118
- if (op.children?.length) {
119
- op.children = prepareOptions(op.children)
120
- }
121
- return isString(op) || isNumber(op) ? { value: op, label: op, text: op } : { text: op.label, ...op }
122
- })
123
- return options
124
- }
125
-
126
- //内部方法,为了useOptionTrait实现单次请求,避免重复请求
127
- const recordOptionsUrl = {}
128
- const optionsFetcher = (props) => {
129
- return new Promise((resolve) => {
130
- useFetch()
131
- .get(props.url)
132
- .then((items) => {
133
- if (props.afterFetched) {
134
- items = props.afterFetched(items)
135
- }
136
- resolve(items)
137
- })
138
- })
139
- }
140
- /**
141
- * 初始化选项
142
- * @param options
143
- * @param props
144
- * @param {Array|Function} [defaultOptions]
145
- *
146
- * @return void
147
- */
148
- export const useOptionTrait = async (options, props, defaultOptions) => {
149
- options.value = prepareOptions(props.options)
150
-
151
- const fetchData = async (props) => {
152
- if (recordOptionsUrl[props.url]) {
153
- return recordOptionsUrl[props.url]
154
- }
155
- recordOptionsUrl[props.url] = optionsFetcher(props)
156
-
157
- const result = await recordOptionsUrl[props.url]
158
- recordOptionsUrl[props.url] = null
159
- return new Promise((resolve) => {
160
- resolve(result)
161
- })
162
- }
163
-
164
- watch(
165
- () => props.options,
166
- () => {
167
- options.value = prepareOptions(props.options)
168
- },
169
- )
170
-
171
- if (!options.value.length) {
172
- if (props.url) {
173
- if (props.urlCache && useCache(props.url).get()) {
174
- options.value = useCache(props.url).get()
175
- } else {
176
- fetchData(props).then((items) => {
177
- options.value = items
178
- if (props.urlCache) {
179
- useCache(props.url).set(items)
180
- }
181
- })
182
- }
183
- } else if (defaultOptions) {
184
- options.value = defaultOptions
185
- }
186
- }
187
- }
1
+ import { cloneDeep, isFunction, isNumber, isString } from "lodash-es"
2
+ import { watch } from "vue"
3
+ import { useCache, useFetch } from "../hooks"
4
+
5
+ /**
6
+ * 通用 field props
7
+ */
8
+ export const defaultFieldProps = {
9
+ /**
10
+ * 输入框左侧文本
11
+ */
12
+ label: { type: String, default: "" },
13
+
14
+ /**
15
+ * 名称,作为提交表单时的标识符
16
+ */
17
+ name: { type: String, default: "" },
18
+
19
+ /**
20
+ * 输入框占位提示文字
21
+ */
22
+ placeholder: { type: String, default: "请填写" },
23
+
24
+ /**
25
+ * 提示文案
26
+ */
27
+ help: { type: [String, Function], default: "" },
28
+
29
+ /**
30
+ * 元素的append slot
31
+ */
32
+ append: { type: [String, Function], default: "" },
33
+
34
+ /**
35
+ * 是否禁用输入框
36
+ */
37
+ disabled: { type: Boolean, default: false },
38
+
39
+ /**
40
+ * 是否显示表单必填星号
41
+ */
42
+ required: { type: Boolean, default: false },
43
+
44
+ /**
45
+ * 是否展示右侧箭头并开启点击反馈
46
+ */
47
+ isLink: { type: Boolean, default: false },
48
+
49
+ /**
50
+ * 是否为只读状态,只读状态下无法输入内容
51
+ */
52
+ readonly: { type: Boolean, default: false },
53
+
54
+ /**
55
+ * 表单校验规则
56
+ */
57
+ rules: { type: Array, default: null },
58
+
59
+ /**
60
+ * 原生 [Field 配置](https://vant-contrib.gitee.io/vant/#/zh-CN/field)
61
+ */
62
+ fieldProps: { type: Object, default: () => ({}) },
63
+
64
+ /**
65
+ * 原生输入组件的 props
66
+ */
67
+ defaultProps: { type: Object, default: () => ({}) },
68
+ }
69
+
70
+ /**
71
+ * 原生 Field 的 slots
72
+ * 用于从组合组件中挑选
73
+ */
74
+ export const defaultFieldSlots = {
75
+ label: () => null,
76
+ input: () => null,
77
+ "left-icon": () => null,
78
+ "right-icon": () => null,
79
+ button: () => null,
80
+ "error-message": () => null,
81
+ extra: () => null,
82
+ }
83
+
84
+ /**
85
+ * 通用的 options props
86
+ */
87
+ export const defaultOptionsProps = {
88
+ /**
89
+ * 选项
90
+ */
91
+ options: { type: [Array, Function], default: () => [] },
92
+
93
+ /**
94
+ * 选项 url
95
+ */
96
+ url: { type: String, default: null },
97
+
98
+ /**
99
+ * 缓存url返回的数据
100
+ */
101
+ urlCache: { type: Boolean, default: true },
102
+
103
+ /**
104
+ * 选项获取后的回调
105
+ */
106
+ afterFetched: { type: Function, default: null },
107
+ }
108
+
109
+ /**
110
+ * Prepare options for select
111
+ *
112
+ * @param options
113
+ * @return {Array}
114
+ */
115
+ export const prepareOptions = (options) => {
116
+ options = isFunction(options) ? options() : options
117
+ options = cloneDeep(options).map((op) => {
118
+ if (op.children?.length) {
119
+ op.children = prepareOptions(op.children)
120
+ }
121
+ return isString(op) || isNumber(op) ? { value: op, label: op, text: op } : { text: op.label, ...op }
122
+ })
123
+ return options
124
+ }
125
+
126
+ //内部方法,为了useOptionTrait实现单次请求,避免重复请求
127
+ const recordOptionsUrl = {}
128
+ const optionsFetcher = (props) => {
129
+ return new Promise((resolve) => {
130
+ useFetch()
131
+ .get(props.url)
132
+ .then((items) => {
133
+ if (props.afterFetched) {
134
+ items = props.afterFetched(items)
135
+ }
136
+ resolve(items)
137
+ })
138
+ })
139
+ }
140
+ /**
141
+ * 初始化选项
142
+ * @param options
143
+ * @param props
144
+ * @param {Array|Function} [defaultOptions]
145
+ *
146
+ * @return void
147
+ */
148
+ export const useOptionTrait = async (options, props, defaultOptions) => {
149
+ options.value = prepareOptions(props.options)
150
+
151
+ const fetchData = async (props) => {
152
+ if (recordOptionsUrl[props.url]) {
153
+ return recordOptionsUrl[props.url]
154
+ }
155
+ recordOptionsUrl[props.url] = optionsFetcher(props)
156
+
157
+ const result = await recordOptionsUrl[props.url]
158
+ recordOptionsUrl[props.url] = null
159
+ return new Promise((resolve) => {
160
+ resolve(result)
161
+ })
162
+ }
163
+
164
+ watch(
165
+ () => props.options,
166
+ () => {
167
+ options.value = prepareOptions(props.options)
168
+ },
169
+ )
170
+
171
+ if (!options.value.length) {
172
+ if (props.url) {
173
+ if (props.urlCache && useCache(props.url).get()) {
174
+ options.value = useCache(props.url).get()
175
+ } else {
176
+ fetchData(props).then((items) => {
177
+ options.value = items
178
+ if (props.urlCache) {
179
+ useCache(props.url).set(items)
180
+ }
181
+ })
182
+ }
183
+ } else if (defaultOptions) {
184
+ options.value = defaultOptions
185
+ }
186
+ }
187
+ }
@@ -1,113 +1,113 @@
1
- /**
2
- * v-auth="'permissions1'"
3
- * v-auth:all="['clickPermissions',['permission1', 'permission2']]"
4
- * v-auth:any="['clickPermissions',['permission1', 'permission2']]"
5
- * v-auth:none="['clickPermissions',['permission1', 'permission2']]"
6
- * @type {*[]}
7
- */
8
-
9
- let defaultPermissions = []
10
-
11
- const authDirective = {
12
- beforeMount(el, binding) {
13
- let { value } = binding
14
- const { arg } = binding
15
-
16
- if (!value) {
17
- return
18
- }
19
-
20
- if (typeof value === "string" || value instanceof String) {
21
- value = [value]
22
- }
23
-
24
- let [permissions, myPermissions] = value
25
-
26
- if (!myPermissions) {
27
- myPermissions = defaultPermissions
28
- }
29
-
30
- if (typeof permissions === "string" || permissions instanceof String) {
31
- permissions = [permissions]
32
- }
33
-
34
- // arg: 'any' 任何一个, 'all' 全部都有,默认, 'none' 都没有
35
-
36
- if (arg === undefined || arg === "all") {
37
- if (!permissions.every((p) => myPermissions.includes(p))) {
38
- el.style.display = "none"
39
- }
40
- } else if (arg === "any") {
41
- if (!permissions.some((p) => myPermissions.includes(p))) {
42
- el.style.display = "none"
43
- }
44
- } else if (arg === "none") {
45
- if (permissions.some((p) => myPermissions.includes(p))) {
46
- el.style.display = "none"
47
- }
48
- }
49
- },
50
- }
51
-
52
- /**
53
- * 初始化权限集合
54
- * @param permissions
55
- */
56
- export function setDefaultPermissions(permissions) {
57
- defaultPermissions = permissions
58
- }
59
-
60
- function auth(value, arg) {
61
- if (!value) {
62
- return true
63
- }
64
-
65
- if (typeof value === "string" || value instanceof String) {
66
- value = [value]
67
- }
68
-
69
- let [permissions, myPermissions] = value
70
-
71
- if (!myPermissions) {
72
- myPermissions = defaultPermissions
73
- }
74
-
75
- if (typeof permissions === "string" || permissions instanceof String) {
76
- permissions = [permissions]
77
- }
78
-
79
- // arg: 'any' 任何一个, 'all' 全部都有,默认, 'none' 都没有
80
-
81
- if (arg === undefined || arg === "all") {
82
- if (!permissions.every((p) => myPermissions.includes(p))) {
83
- return false
84
- }
85
- } else if (arg === "any") {
86
- if (!permissions.some((p) => myPermissions.includes(p))) {
87
- return false
88
- }
89
- } else if (arg === "none") {
90
- if (permissions.some((p) => myPermissions.includes(p))) {
91
- return false
92
- }
93
- }
94
- return true
95
- }
96
-
97
- export default {
98
- /**
99
- *
100
- * @param app
101
- * @param {Object} [options]
102
- * @param {Object} [options.defaultPermissions]
103
- */
104
- install(app, options) {
105
- app.directive("auth", authDirective)
106
- app.config.globalProperties.$auth = auth
107
- app.provide("auth", auth)
108
-
109
- if (options && options.defaultPermissions) {
110
- setDefaultPermissions(options.defaultPermissions)
111
- }
112
- },
113
- }
1
+ /**
2
+ * v-auth="'permissions1'"
3
+ * v-auth:all="['clickPermissions',['permission1', 'permission2']]"
4
+ * v-auth:any="['clickPermissions',['permission1', 'permission2']]"
5
+ * v-auth:none="['clickPermissions',['permission1', 'permission2']]"
6
+ * @type {*[]}
7
+ */
8
+
9
+ let defaultPermissions = []
10
+
11
+ const authDirective = {
12
+ beforeMount(el, binding) {
13
+ let { value } = binding
14
+ const { arg } = binding
15
+
16
+ if (!value) {
17
+ return
18
+ }
19
+
20
+ if (typeof value === "string" || value instanceof String) {
21
+ value = [value]
22
+ }
23
+
24
+ let [permissions, myPermissions] = value
25
+
26
+ if (!myPermissions) {
27
+ myPermissions = defaultPermissions
28
+ }
29
+
30
+ if (typeof permissions === "string" || permissions instanceof String) {
31
+ permissions = [permissions]
32
+ }
33
+
34
+ // arg: 'any' 任何一个, 'all' 全部都有,默认, 'none' 都没有
35
+
36
+ if (arg === undefined || arg === "all") {
37
+ if (!permissions.every((p) => myPermissions.includes(p))) {
38
+ el.style.display = "none"
39
+ }
40
+ } else if (arg === "any") {
41
+ if (!permissions.some((p) => myPermissions.includes(p))) {
42
+ el.style.display = "none"
43
+ }
44
+ } else if (arg === "none") {
45
+ if (permissions.some((p) => myPermissions.includes(p))) {
46
+ el.style.display = "none"
47
+ }
48
+ }
49
+ },
50
+ }
51
+
52
+ /**
53
+ * 初始化权限集合
54
+ * @param permissions
55
+ */
56
+ export function setDefaultPermissions(permissions) {
57
+ defaultPermissions = permissions
58
+ }
59
+
60
+ function auth(value, arg) {
61
+ if (!value) {
62
+ return true
63
+ }
64
+
65
+ if (typeof value === "string" || value instanceof String) {
66
+ value = [value]
67
+ }
68
+
69
+ let [permissions, myPermissions] = value
70
+
71
+ if (!myPermissions) {
72
+ myPermissions = defaultPermissions
73
+ }
74
+
75
+ if (typeof permissions === "string" || permissions instanceof String) {
76
+ permissions = [permissions]
77
+ }
78
+
79
+ // arg: 'any' 任何一个, 'all' 全部都有,默认, 'none' 都没有
80
+
81
+ if (arg === undefined || arg === "all") {
82
+ if (!permissions.every((p) => myPermissions.includes(p))) {
83
+ return false
84
+ }
85
+ } else if (arg === "any") {
86
+ if (!permissions.some((p) => myPermissions.includes(p))) {
87
+ return false
88
+ }
89
+ } else if (arg === "none") {
90
+ if (permissions.some((p) => myPermissions.includes(p))) {
91
+ return false
92
+ }
93
+ }
94
+ return true
95
+ }
96
+
97
+ export default {
98
+ /**
99
+ *
100
+ * @param app
101
+ * @param {Object} [options]
102
+ * @param {Object} [options.defaultPermissions]
103
+ */
104
+ install(app, options) {
105
+ app.directive("auth", authDirective)
106
+ app.config.globalProperties.$auth = auth
107
+ app.provide("auth", auth)
108
+
109
+ if (options && options.defaultPermissions) {
110
+ setDefaultPermissions(options.defaultPermissions)
111
+ }
112
+ },
113
+ }
@@ -1,4 +1,4 @@
1
- import auth, { setDefaultPermissions } from "./auth"
2
-
3
- export { auth, setDefaultPermissions }
4
- //export * from "./auth"
1
+ import auth, { setDefaultPermissions } from "./auth"
2
+
3
+ export { auth, setDefaultPermissions }
4
+ //export * from "./auth"