haiwei-module-common 1.0.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 (68) hide show
  1. package/.browserslistrc +2 -0
  2. package/.eslintrc.js +18 -0
  3. package/.prettierrc +6 -0
  4. package/.vscode/settings.json +10 -0
  5. package/babel.config.js +10 -0
  6. package/package.json +41 -0
  7. package/postcss.config.js +5 -0
  8. package/script/npm_install.bat +4 -0
  9. package/script/npm_install.ps1 +10 -0
  10. package/script/npm_publish.bat +4 -0
  11. package/script/npm_publish.ps1 +10 -0
  12. package/script/npm_update.bat +4 -0
  13. package/script/npm_update.ps1 +10 -0
  14. package/src/api/components/area.js +22 -0
  15. package/src/api/components/attachment.js +30 -0
  16. package/src/api/components/dict.js +24 -0
  17. package/src/api/components/dictGroup.js +17 -0
  18. package/src/api/components/dictItem.js +10 -0
  19. package/src/api/components/mediaType.js +10 -0
  20. package/src/api/index.js +11 -0
  21. package/src/components/area-select/index.vue +147 -0
  22. package/src/components/area-select/item.vue +85 -0
  23. package/src/components/attachment-download/index.vue +70 -0
  24. package/src/components/attachment-img/index.vue +58 -0
  25. package/src/components/attachment-upload-img/index.vue +244 -0
  26. package/src/components/attachment-upload-single/index.vue +143 -0
  27. package/src/components/ccdieet-upload/index_.vue +51 -0
  28. package/src/components/config-common/index.vue +41 -0
  29. package/src/components/dict-checkbox/index.vue +29 -0
  30. package/src/components/dict-radio/index.vue +29 -0
  31. package/src/components/dict-select/index.vue +29 -0
  32. package/src/components/dict-tree/index.vue +97 -0
  33. package/src/components/index.js +10 -0
  34. package/src/components/upload-mixins.js +118 -0
  35. package/src/config/index.js +11 -0
  36. package/src/index.js +23 -0
  37. package/src/main.js +9 -0
  38. package/src/module.js +10 -0
  39. package/src/routes/index.js +3 -0
  40. package/src/store/index.js +3 -0
  41. package/src/views/area/components/cascader/index.vue +16 -0
  42. package/src/views/area/components/save/index.vue +96 -0
  43. package/src/views/area/index/cols.js +47 -0
  44. package/src/views/area/index/index.vue +126 -0
  45. package/src/views/area/index/page.js +42 -0
  46. package/src/views/attachment/index/cols.js +59 -0
  47. package/src/views/attachment/index/index.vue +60 -0
  48. package/src/views/attachment/index/page.js +36 -0
  49. package/src/views/dict/components/save/index.vue +63 -0
  50. package/src/views/dict/index/cols.js +35 -0
  51. package/src/views/dict/index/index.vue +79 -0
  52. package/src/views/dict/index/page.js +49 -0
  53. package/src/views/dictGroup/components/save/index.vue +57 -0
  54. package/src/views/dictGroup/components/select/index.vue +14 -0
  55. package/src/views/dictGroup/index/cols.js +36 -0
  56. package/src/views/dictGroup/index/index.vue +67 -0
  57. package/src/views/dictGroup/index/page.js +42 -0
  58. package/src/views/dictItem/components/extend-editor/index.vue +57 -0
  59. package/src/views/dictItem/components/index/cols.js +40 -0
  60. package/src/views/dictItem/components/index/index.vue +86 -0
  61. package/src/views/dictItem/components/save/index.vue +94 -0
  62. package/src/views/dictItem/components/tree/index.vue +133 -0
  63. package/src/views/dictItem/index.vue +51 -0
  64. package/src/views/mediaType/components/save/index.vue +45 -0
  65. package/src/views/mediaType/index/cols.js +16 -0
  66. package/src/views/mediaType/index/index.vue +55 -0
  67. package/src/views/mediaType/index/page.js +42 -0
  68. package/vue.config.js +108 -0
@@ -0,0 +1,244 @@
1
+ <template>
2
+ <div :class="['nm-attachment-upload-img', disabled ? 'disabled' : '']" :style="style" v-loading="loading">
3
+ <div v-if="disabled" class="disabled-bg"></div>
4
+ <el-upload v-bind="uploadOptions">
5
+ <nm-attachment-img v-show="id" :id="id" class="preview" />
6
+ <div v-show="!id" class="text-box">
7
+ <i class="el-icon-upload" :style="{ fontSize: iconSize }"></i>
8
+ <div class="text">
9
+ <slot name="text">
10
+ 将文件拖到此处,或
11
+ <em>点击上传</em>
12
+ </slot>
13
+ </div>
14
+ <div class="tip">
15
+ <slot name="tip">{{ tip }}</slot>
16
+ </div>
17
+ </div>
18
+ </el-upload>
19
+ <span v-show="id" class="remove" @click="reset">
20
+ <nm-icon name="close" />
21
+ </span>
22
+ </div>
23
+ </template>
24
+ <script>
25
+ import mixins from '../upload-mixins'
26
+
27
+ // 接口
28
+ const api = $api.common.attachment
29
+
30
+ export default {
31
+ mixins: [mixins],
32
+ props: {
33
+ /** 宽度 */
34
+ width: {
35
+ type: String,
36
+ default: '100px'
37
+ },
38
+ /** 高度 */
39
+ height: {
40
+ type: String,
41
+ default: '150px'
42
+ },
43
+ /** 文章说明 */
44
+ text: String,
45
+ /** 底部提示语 */
46
+ tip: String,
47
+ /** 接受上传的文件类型 */
48
+ accept: {
49
+ type: String,
50
+ default: 'image/jpeg,image/png'
51
+ },
52
+ /** 可接受文件类型 */
53
+ fileType: {
54
+ type: Array,
55
+ default() {
56
+ return ['jpg', 'jpeg', 'png']
57
+ }
58
+ },
59
+ /** 图标大小 */
60
+ iconSize: {
61
+ type: String,
62
+ default: '5em'
63
+ }
64
+ },
65
+ computed: {
66
+ uploadOptions() {
67
+ return {
68
+ action: api.getUploadUrl(),
69
+ headers: {
70
+ Authorization: 'Bearer ' + this.accessToken
71
+ },
72
+ data: {
73
+ module: this.module,
74
+ group: this.group,
75
+ name: this.name,
76
+ auth: this.auth
77
+ },
78
+ accept: this.accept,
79
+ drag: this.drag,
80
+ autoUpload: true,
81
+ showFileList: false,
82
+ beforeUpload: this.onBeforeUpload,
83
+ onSuccess: this.onSuccess,
84
+ onError: this.onError,
85
+ disabled: this.disabled
86
+ }
87
+ },
88
+ style() {
89
+ return { width: this.width, height: this.height }
90
+ }
91
+ },
92
+ methods: {
93
+ onBeforeUpload(file) {
94
+ // 文件格式验证
95
+ if (!this.verifyFileType(file)) {
96
+ return false
97
+ }
98
+ // 验证是否超出最大上传数
99
+ if (this.maxSizeBytes && file.size > this.maxSizeBytes) {
100
+ this._error(`文件大小${this.getSizeUnit(file.size)}超过了最大允许值${this.maxSize}`)
101
+ return false
102
+ }
103
+ if (this.beforeUpload && typeof this.beforeUpload === 'function' && !this.beforeUpload(file)) {
104
+ return false
105
+ }
106
+
107
+ this.loading = true
108
+ return true
109
+ },
110
+ onSuccess(res, file) {
111
+ const data = res.data
112
+ if (data.code === 1) {
113
+ this.id = data.data.id
114
+ this.$emit('input', this.id)
115
+ this.$emit('success', res, file)
116
+ } else {
117
+ this.$emit('error')
118
+ }
119
+ this.loading = false
120
+ },
121
+ reset() {
122
+ this.id = ''
123
+ this.$emit('input', this.id)
124
+ }
125
+ }
126
+ }
127
+ </script>
128
+
129
+ <style lang="scss">
130
+ .nm-attachment-upload-img {
131
+ position: relative;
132
+ display: inline-block;
133
+ box-sizing: border-box;
134
+ border: 1px dashed #ccc;
135
+ background-color: #fff;
136
+ text-align: center;
137
+ color: #8c939d;
138
+ cursor: pointer;
139
+ border-radius: 5px;
140
+ overflow: hidden;
141
+
142
+ > div {
143
+ width: 100%;
144
+ height: 100%;
145
+ }
146
+
147
+ .preview {
148
+ width: 100%;
149
+ height: 100%;
150
+ line-height: 100%;
151
+ text-align: center;
152
+ img {
153
+ max-width: 100%;
154
+ max-height: 100%;
155
+ }
156
+ .no-picture {
157
+ font-size: 2em;
158
+ }
159
+ }
160
+
161
+ .el-upload {
162
+ width: 100%;
163
+ height: 100%;
164
+ }
165
+
166
+ .el-upload-dragger {
167
+ position: relative;
168
+ top: 50%;
169
+ border: none;
170
+ margin-top: -50%;
171
+ width: 100%;
172
+ height: auto;
173
+ .text-box {
174
+ font-size: 14px;
175
+
176
+ .el-icon-upload {
177
+ margin: auto;
178
+ font-size: 5em;
179
+ color: #c0c4cc !important;
180
+ }
181
+
182
+ em {
183
+ color: #409eff;
184
+ font-style: normal;
185
+ }
186
+
187
+ .text {
188
+ font-size: 13px;
189
+ line-height: 130%;
190
+ }
191
+ }
192
+ }
193
+
194
+ .el-loading-spinner {
195
+ line-height: 100%;
196
+ }
197
+
198
+ .remove {
199
+ position: absolute;
200
+ display: none;
201
+ top: 0;
202
+ right: 0;
203
+ width: 30px;
204
+ height: 30px;
205
+ line-height: 27px;
206
+ border-radius: 15px;
207
+ background-color: #f56c6c;
208
+ color: #ccc;
209
+ font-size: 16px;
210
+
211
+ &:hover {
212
+ color: #fff;
213
+ }
214
+ }
215
+
216
+ &:hover {
217
+ border-color: #409eff;
218
+
219
+ .remove {
220
+ display: inline-block;
221
+ }
222
+ }
223
+
224
+ &.disabled:hover {
225
+ border: 1px dashed #ccc;
226
+
227
+ .remove {
228
+ display: none;
229
+ }
230
+ }
231
+
232
+ .disabled-bg {
233
+ position: absolute;
234
+ top: 0;
235
+ left: 0;
236
+ width: 100%;
237
+ height: 100%;
238
+ background-color: #f5f7fa;
239
+ z-index: 999;
240
+ opacity: 0.5;
241
+ cursor: not-allowed;
242
+ }
243
+ }
244
+ </style>
@@ -0,0 +1,143 @@
1
+ <template>
2
+ <div class="nm-attachment-upload-single">
3
+ <div class="input">
4
+ <el-input :value="fileName" readonly :disabled="disabled" />
5
+ </div>
6
+ <div class="button">
7
+ <el-upload ref="upload" v-bind="uploadOptions">
8
+ <nm-button :type="btnType" text="上传" :icon="icon_" @click="onClick" :loading="loading" />
9
+ </el-upload>
10
+ </div>
11
+ </div>
12
+ </template>
13
+ <script>
14
+ import mixins from '../upload-mixins'
15
+
16
+ // 接口
17
+ const api = $api.common.attachment
18
+
19
+ export default {
20
+ mixins: [mixins],
21
+ data() {
22
+ return {
23
+ fileName: ''
24
+ }
25
+ },
26
+ props: {
27
+ /** 按钮类型 */
28
+ btnType: {
29
+ type: String,
30
+ default: 'primary'
31
+ },
32
+ /** 不显示按钮图标 */
33
+ noIcon: Boolean
34
+ },
35
+ computed: {
36
+ uploadOptions() {
37
+ return {
38
+ action: api.getUploadUrl(),
39
+ headers: {
40
+ Authorization: 'Bearer ' + this.accessToken
41
+ },
42
+ data: {
43
+ module: this.module,
44
+ group: this.group,
45
+ name: this.name,
46
+ auth: this.auth
47
+ },
48
+ accept: this.accept,
49
+ drag: false,
50
+ autoUpload: true,
51
+ showFileList: false,
52
+ beforeUpload: this.onBeforeUpload,
53
+ onSuccess: this.onSuccess,
54
+ onError: this.onError,
55
+ disabled: this.disabled
56
+ }
57
+ },
58
+ icon_() {
59
+ return this.loading ? 'loading' : this.noIcon ? '' : 'upload'
60
+ }
61
+ },
62
+ methods: {
63
+ onBeforeUpload(file) {
64
+ // 文件格式验证
65
+ if (!this.verifyFileType(file)) {
66
+ return false
67
+ }
68
+ // 验证是否超出最大上传数
69
+ if (this.maxSizeBytes && file.size > this.maxSizeBytes) {
70
+ this._error(`文件大小${this.getSizeUnit(file.size)}超过了最大允许值${this.maxSize}`)
71
+ return false
72
+ }
73
+ if (this.beforeUpload && typeof this.beforeUpload === 'function' && !this.beforeUpload(file)) {
74
+ return false
75
+ }
76
+
77
+ this.loading = true
78
+ return true
79
+ },
80
+ onSuccess(res, file) {
81
+ const data = res.data
82
+ if (data.code === 1) {
83
+ this.id = data.data.id
84
+ this.fileName = file.name
85
+ this.$emit('input', this.id)
86
+ this.$emit('success', res, file)
87
+ } else {
88
+ this.$emit('error')
89
+ }
90
+ this.loading = false
91
+ },
92
+ reset() {
93
+ this.id = ''
94
+ this.fileName = ''
95
+ this.$emit('input', this.id)
96
+ },
97
+ onClick() {
98
+ if (this.loading) {
99
+ return
100
+ }
101
+ this.$refs.upload.clearFiles()
102
+ }
103
+ },
104
+ watch: {
105
+ name(val) {
106
+ this.fileName = val
107
+ }
108
+ }
109
+ }
110
+ </script>
111
+
112
+ <style lang="scss">
113
+ .nm-attachment-upload-single {
114
+ position: relative;
115
+ padding-right: 80px;
116
+ width: 100%;
117
+ box-sizing: border-box;
118
+ .input {
119
+ .el-input__inner {
120
+ border-top-right-radius: 0;
121
+ border-bottom-right-radius: 0;
122
+ }
123
+ }
124
+ .button {
125
+ position: absolute;
126
+ right: 0;
127
+ top: 0;
128
+ width: 80px;
129
+ height: 100%;
130
+
131
+ > div,
132
+ .el-upload,
133
+ .nm-button {
134
+ height: 100%;
135
+ }
136
+
137
+ .nm-button {
138
+ border-top-left-radius: 0;
139
+ border-bottom-left-radius: 0;
140
+ }
141
+ }
142
+ }
143
+ </style>
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <div>
3
+ <nm-button icon="upload" @click="visible = true" />
4
+ <nm-dialog title="上传图片" icon="upload" height="400px" footer :visible.sync="visible">
5
+ <div style="margin:20px;text-algin:center;">
6
+ <nm-attachment-upload-img v-bind="options" @success="onUploadSuccess">
7
+ <template v-slot:text>请选择文件</template>
8
+ </nm-attachment-upload-img>
9
+ </div>
10
+ <template v-slot:footer>
11
+ <nm-button type="success" text="确定" @click="onClick" />
12
+ </template>
13
+ </nm-dialog>
14
+ </div>
15
+ </template>
16
+ <script>
17
+ export default {
18
+ data() {
19
+ return {
20
+ value_: this.value,
21
+ visible: false,
22
+ options: {
23
+ module: 'Common',
24
+ group: 'DictTest',
25
+ maxSize: '500kb',
26
+ width: '100px',
27
+ height: '120px',
28
+ iconSize: '3em'
29
+ },
30
+ url: ''
31
+ }
32
+ },
33
+ props: {
34
+ value: String
35
+ },
36
+ methods: {
37
+ onUploadSuccess(res) {
38
+ this.url = res.data.data.url
39
+ },
40
+ onClick() {
41
+ this.$emit('success', this.url)
42
+ this.visible = false
43
+ }
44
+ },
45
+ watch: {
46
+ value(val) {
47
+ if (val !== this.value_) this.value_ = val
48
+ }
49
+ }
50
+ }
51
+ </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <nm-form-page v-bind="form">
3
+ <el-row>
4
+ <el-col :span="10" :offset="1">
5
+ <el-form-item label="字典缓存:" prop="dictCacheEnabled">
6
+ <el-switch v-model="form.model.dictCacheEnabled" />
7
+ </el-form-item>
8
+ </el-col>
9
+ </el-row>
10
+ </nm-form-page>
11
+ </template>
12
+ <script>
13
+ import module from '../../module'
14
+ const { edit, update } = $api.admin.config
15
+ export default {
16
+ data() {
17
+ return {
18
+ code: module.code,
19
+ type: 1,
20
+ form: {
21
+ header: false,
22
+ action: this.update,
23
+ labelWidth: '200px',
24
+ model: {
25
+ dictCacheEnabled: false
26
+ }
27
+ }
28
+ }
29
+ },
30
+ methods: {
31
+ update() {
32
+ return update({ type: this.type, code: this.code, json: JSON.stringify(this.form.model) })
33
+ }
34
+ },
35
+ created() {
36
+ edit({ type: this.type, code: this.code }).then(data => {
37
+ this.form.model = data
38
+ })
39
+ }
40
+ }
41
+ </script>
@@ -0,0 +1,29 @@
1
+ <script>
2
+ import { mixins } from 'haiwei-ui'
3
+
4
+ const api = $api.common.dict
5
+
6
+ export default {
7
+ mixins: [mixins.checkbox],
8
+ data() {
9
+ return {
10
+ action: this.query
11
+ }
12
+ },
13
+ props: {
14
+ group: {
15
+ type: String,
16
+ required: true
17
+ },
18
+ code: {
19
+ type: String,
20
+ required: true
21
+ }
22
+ },
23
+ methods: {
24
+ query() {
25
+ return api.select({ group: this.group, code: this.code })
26
+ }
27
+ }
28
+ }
29
+ </script>
@@ -0,0 +1,29 @@
1
+ <script>
2
+ import { mixins } from 'haiwei-ui'
3
+
4
+ const api = $api.common.dict
5
+
6
+ export default {
7
+ mixins: [mixins.radio],
8
+ data() {
9
+ return {
10
+ action: this.query
11
+ }
12
+ },
13
+ props: {
14
+ group: {
15
+ type: String,
16
+ required: true
17
+ },
18
+ code: {
19
+ type: String,
20
+ required: true
21
+ }
22
+ },
23
+ methods: {
24
+ query() {
25
+ return api.select({ group: this.group, code: this.code })
26
+ }
27
+ }
28
+ }
29
+ </script>
@@ -0,0 +1,29 @@
1
+ <script>
2
+ import { mixins } from 'haiwei-ui'
3
+
4
+ const api = $api.common.dict
5
+
6
+ export default {
7
+ mixins: [mixins.select],
8
+ data() {
9
+ return {
10
+ action: this.query
11
+ }
12
+ },
13
+ props: {
14
+ group: {
15
+ type: String,
16
+ required: true
17
+ },
18
+ code: {
19
+ type: String,
20
+ required: true
21
+ }
22
+ },
23
+ methods: {
24
+ query() {
25
+ return api.select({ group: this.group, code: this.code })
26
+ }
27
+ }
28
+ }
29
+ </script>
@@ -0,0 +1,97 @@
1
+ <script>
2
+ import { mixins } from 'haiwei-ui'
3
+ const { tree } = $api.common.dict
4
+
5
+ export default {
6
+ mixins: [mixins.treeSelect],
7
+ data() {
8
+ return {
9
+ action: this.query
10
+ }
11
+ },
12
+ props: {
13
+ group: {
14
+ type: String,
15
+ required: true
16
+ },
17
+ code: {
18
+ type: String,
19
+ required: true
20
+ },
21
+ collapseAll: {
22
+ type: Boolean,
23
+ default: true
24
+ }
25
+ },
26
+ computed: {
27
+ /**已选中的值 */
28
+ value_() {
29
+ let sl = this.selection
30
+ return this.multiple ? sl.map(m => m.value) : sl.length > 0 ? sl[0].value : ''
31
+ }
32
+ },
33
+ methods: {
34
+ query() {
35
+ return tree({ group: this.group, code: this.code })
36
+ },
37
+ refreshTree() {
38
+ this.loading = true
39
+ this.action().then(data => {
40
+ this.title_ = data.label
41
+ this.treeOptions.data = data.children
42
+ this.change()
43
+ this.loading = false
44
+ })
45
+ },
46
+ /**
47
+ * @description 选项更改处理
48
+ */
49
+ change() {
50
+ if (!this.value) return
51
+
52
+ let data = this.treeOptions.data
53
+ if (data.length < 1) return
54
+
55
+ let value = this.multiple ? this.value : [this.value]
56
+ let ids = this.getIds(data, value)
57
+
58
+ //设置显示文本
59
+ this.setLabel(ids)
60
+ //清除已选项
61
+ this.selection = []
62
+ //要展开的选项
63
+ this.treeOptions.defaultExpandedKeys = ids
64
+
65
+ this.$nextTick(() => {
66
+ this.setCheckedKeys(ids)
67
+ this.$emit('change', this.value_, this.selection_)
68
+ })
69
+ },
70
+ getIds(list, value, ids) {
71
+ if (!ids) ids = []
72
+ list.forEach(m => {
73
+ if (value.includes(m.item.value)) {
74
+ ids.push(m.id)
75
+ }
76
+
77
+ if (m.children && m.children.length > 0) {
78
+ ids.concat(this.getIds(m.children, value, ids))
79
+ }
80
+ })
81
+ return ids
82
+ },
83
+ /**保存 */
84
+ save() {
85
+ if (this.multiple && this.multipleLimit > 0 && this.selection.length > this.multipleLimit) {
86
+ this.showLimitMsg()
87
+ return
88
+ }
89
+ let sl = this.selection
90
+ this.setLabel(this.multiple ? sl.map(m => m.id) : sl.length > 0 ? [sl[0].id] : [])
91
+ this.$emit('input', this.value_)
92
+ this.$emit('change', this.value_, this.selection_)
93
+ this.visible = false
94
+ }
95
+ }
96
+ }
97
+ </script>
@@ -0,0 +1,10 @@
1
+ import library from 'haiwei-ui/packages/library'
2
+ let components = []
3
+ const requireComponent = require.context('./', true, /index\.vue$/)
4
+ requireComponent.keys().map(fileName => {
5
+ components.push({
6
+ name: `${library.prefix.toLowerCase()}-${fileName.split('/')[1]}`,
7
+ component: requireComponent(fileName).default
8
+ })
9
+ })
10
+ export default components