@netang/quasar 0.0.58 → 0.0.59

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.
@@ -0,0 +1,277 @@
1
+ <template>
2
+ <slot
3
+ :scope="current"
4
+ :emit="emitValue"
5
+ />
6
+ </template>
7
+
8
+ <script>
9
+ import { ref, watch } from 'vue'
10
+ import $n_isFunction from 'lodash/isFunction'
11
+ import $n_uniq from 'lodash/uniq'
12
+
13
+ import $n_isValidArray from '@netang/utils/isValidArray'
14
+ import $n_split from '@netang/utils/split'
15
+ import $n_isValidValue from '@netang/utils/isValidValue'
16
+ import $n_trimString from '@netang/utils/trimString'
17
+
18
+ export default {
19
+
20
+ /**
21
+ * 关闭组件 attribute 透传行为
22
+ */
23
+ inheritAttrs: false,
24
+
25
+ /**
26
+ * 标识
27
+ */
28
+ name: 'NArr',
29
+
30
+ /**
31
+ * 声明属性
32
+ */
33
+ props: {
34
+ // 值 v-model
35
+ modelValue: {
36
+ required: true,
37
+ },
38
+ // 修改前值
39
+ before: Function,
40
+ // 修改后值
41
+ after: Function,
42
+ // 不自动触发更新
43
+ noEmit: Boolean,
44
+ },
45
+
46
+ /**
47
+ * 声明事件
48
+ */
49
+ emits: [
50
+ 'update:modelValue',
51
+ ],
52
+
53
+ /**
54
+ * 组合式
55
+ */
56
+ setup(props, { emit }) {
57
+
58
+ // ==========【数据】============================================================================================
59
+
60
+ // 计数器
61
+ let num = 1
62
+
63
+ // 当前值
64
+ const currentValue = ref({
65
+ value: formatModelValue(props.modelValue),
66
+ })
67
+
68
+ // 如果是自动触发更新
69
+ if (! props.noEmit) {
70
+ // 触发更新值
71
+ // 此处用于判断声明值是否有改变
72
+ emitValue()
73
+ }
74
+
75
+ // ==========【监听数据】=========================================================================================
76
+
77
+ /**
78
+ * 监听声明值
79
+ */
80
+ watch(() => props.modelValue, function (val) {
81
+
82
+ // 格式化声明值
83
+ current.value.value = formatModelValue(val)
84
+
85
+ }, {
86
+ // 深度监听
87
+ deep: true,
88
+ })
89
+
90
+ /**
91
+ * 监听当前值
92
+ */
93
+ watch(current, function (value) {
94
+
95
+ // 如果是自动触发更新
96
+ if (! props.noEmit) {
97
+
98
+ // 立即执行触发更新值
99
+ emitValue(value.value)
100
+ }
101
+
102
+ }, {
103
+ // 深度监听
104
+ deep: true,
105
+ })
106
+
107
+ // ==========【方法】=============================================================================================
108
+
109
+ /**
110
+ * 格式化声明值
111
+ */
112
+ function formatModelValue(value) {
113
+ return $n_isFunction(props.before)
114
+ // 如果有修改前值方法
115
+ ? props.before({ value, formatArray, formatString })
116
+ // 返回值
117
+ : value
118
+ }
119
+
120
+ /**
121
+ * 触发更新值
122
+ */
123
+ function emitValue() {
124
+
125
+ // if (
126
+ // value !== void 0
127
+ // && typeof value === 'object'
128
+ // && value instanceof Event
129
+ // ) {
130
+ // // 停止冒泡
131
+ // value.stopPropagation()
132
+ //
133
+ // // 获取当前值
134
+ // value = current.value.value
135
+ // }
136
+
137
+ // 获取当前值
138
+ const value = current.value.value
139
+
140
+ // 获取新值
141
+ const newValue = $n_isFunction(props.after) ?
142
+ // 如果有修改提交值方法
143
+ props.after({ value, formatArray, formatString })
144
+ // 否则返回当前值
145
+ : value
146
+
147
+ // 如果值有改变
148
+ if (newValue !== props.modelValue) {
149
+
150
+ // 触发更新值
151
+ emit('update:modelValue', newValue)
152
+ }
153
+ }
154
+
155
+ /**
156
+ * 格式化数组
157
+ */
158
+ function formatArray(val, params) {
159
+
160
+ const o = Object.assign({
161
+ // 是否去重
162
+ unique: true,
163
+ // 分隔符
164
+ separator: ',',
165
+ // 是否给每个值去除首位空格
166
+ trim: true,
167
+ // 验证每个值是否为有效字符串/数字
168
+ isValidValue: true,
169
+ // 是否转字符串
170
+ toString: false,
171
+ }, params)
172
+
173
+ val = $n_isValidArray(val) ? val : []
174
+
175
+ // 如果数组有值
176
+ if (val.length) {
177
+
178
+ // 是否给每个值去除首位空格
179
+ if (o.trim) {
180
+ val = val.map(e => $n_trimString(e))
181
+ }
182
+
183
+ // 是否验证每个值是否为有效字符串/数字
184
+ if (o.isValidValue) {
185
+ val = val.filter(val => $n_isValidValue(val))
186
+ }
187
+
188
+ // 去重
189
+ if (o.unique) {
190
+ val = $n_uniq(val)
191
+ }
192
+ }
193
+
194
+ // 如果转字符串
195
+ if (o.toString) {
196
+ // 合并为字符串
197
+ return val.join(o.separator)
198
+ }
199
+
200
+ return []
201
+ }
202
+
203
+ /**
204
+ * 格式化字符串
205
+ */
206
+ function formatString(val, params) {
207
+
208
+ const o = Object.assign({
209
+ // 是否给每个值去除首位空格
210
+ trim: true,
211
+ // 替换内容
212
+ replace: /\n|,|,|\s+/g,
213
+ // 是否去重
214
+ unique: true,
215
+ // 分隔符
216
+ separator: ',',
217
+ // 验证每个值是否为有效字符串/数字
218
+ isValidValue: true,
219
+ // 是否转数组
220
+ toArray: false,
221
+ }, params)
222
+
223
+ // 是否去除首尾空格
224
+ if (o.trim) {
225
+ // 去除首尾空格
226
+ val = $n_trimString(val)
227
+
228
+ // 否则转字符串
229
+ } else {
230
+ val = $n_isValidValue(val) ? String(val) : ''
231
+ }
232
+
233
+ // 如果有分割符
234
+ if ($n_isValidValue(o.separator, true)) {
235
+
236
+ // 是否替换
237
+ if (o.replace) {
238
+ val = val.replace(o.replace, o.separator)
239
+ }
240
+
241
+ // 分隔成数组
242
+ val = $n_split(val, o.separator)
243
+
244
+ // 如果去重
245
+ if (o.unique) {
246
+ val = $n_uniq(val)
247
+ }
248
+
249
+ // 如果验证每个值是否为有效字符串/数字
250
+ if (o.isValidValue) {
251
+ val = val.filter(val => $n_isValidValue(val))
252
+ }
253
+
254
+ // 如果转数组
255
+ if (o.toArray) {
256
+ // 则直接返回
257
+ return val
258
+ }
259
+
260
+ // 返回分隔符隔开的字符串
261
+ return val.join(o.separator)
262
+ }
263
+
264
+ return o.toArray ? [ val ] : ''
265
+ }
266
+
267
+ // ==========【返回】=============================================================================================
268
+
269
+ return {
270
+ // 当前值
271
+ current,
272
+ // 触发更新值
273
+ emitValue,
274
+ }
275
+ }
276
+ }
277
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/uploader.js CHANGED
@@ -5,6 +5,8 @@ import $n_has from 'lodash/has'
5
5
  import $n_get from 'lodash/get'
6
6
  import $n_toLower from 'lodash/toLower'
7
7
  import $n_findIndex from 'lodash/findIndex'
8
+ import $n_uniq from 'lodash/uniq'
9
+ import $n_find from 'lodash/find'
8
10
 
9
11
  import $n_isValidArray from '@netang/utils/isValidArray'
10
12
  import $n_isValidObject from '@netang/utils/isValidObject'
@@ -19,20 +21,16 @@ import $n_run from '@netang/utils/run'
19
21
  import $n_isValidValue from '@netang/utils/isValidValue'
20
22
  import $n_copy from '@netang/utils/copy'
21
23
  import $n_http from '@netang/utils/http'
24
+ import $n_getThrowMessage from '@netang/utils/getThrowMessage'
22
25
 
23
26
  import $n_toast from './toast'
24
27
  import $n_confirm from './confirm'
25
28
  import $n_alert from './alert'
26
-
29
+ import $n_previewImage from './previewImage'
30
+ import $n_getImage from './getImage'
31
+ import $n_getFile from './getFile'
27
32
  import $n_config from './config'
28
33
 
29
- import { configs } from './config'
30
-
31
- const {
32
- // api 文件请求地址
33
- apiFileUrl,
34
- } = configs
35
-
36
34
  import {
37
35
  // 文件类型映射
38
36
  FilE_TYPE,
@@ -198,7 +196,7 @@ function create(params) {
198
196
 
199
197
  // 请求 - 获取文件
200
198
  const { status, data: resExisted } = await $n_http({
201
- url: apiFileUrl + 'get_file',
199
+ url: $n_config('apiFileUrl') + 'get_file',
202
200
  data: {
203
201
  hashs,
204
202
  },
@@ -654,7 +652,7 @@ function create(params) {
654
652
 
655
653
  // 请求 - 检查文件是否存在 hash
656
654
  const { status, data: resExisted } = await $n_http({
657
- url: apiFileUrl + 'check_exist',
655
+ url: $n_config('apiFileUrl') + 'check_exist',
658
656
  data: {
659
657
  hashs: $n_uniq(checkHashs),
660
658
  },
@@ -974,7 +972,7 @@ function create(params) {
974
972
 
975
973
  // 请求 - 修改文件名
976
974
  const { status } = await $n_http({
977
- url: apiFileUrl + 'edit_file_title',
975
+ url: $n_config('apiFileUrl') + 'edit_file_title',
978
976
  data: {
979
977
  hash,
980
978
  title: newTitle,