ci-plus 1.8.9 → 1.9.1

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.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## 历史更新
2
2
 
3
3
  ```js
4
+ 1.9.1
5
+ 1、优化uploadV5.vue组件
6
+ 1.9.0
7
+ 1、uploadV4.vue组件基础上,新增uploadV5.vue组件(新增功能:配置默认选中归属公司选项)
4
8
  1.8.9
5
9
  1、更新uploadV4.vue组件命名重复
6
10
  2、优化一些其他bug
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ci-plus",
3
- "version": "1.8.9",
3
+ "version": "1.9.1",
4
4
  "description": "ci组件库",
5
5
  "main": "./index.ts",
6
6
  "scripts": {
@@ -27,6 +27,7 @@ declare module '@vue/runtime-core' {
27
27
  CiUploadV2: typeof components.UploadV2
28
28
  CiUploadV3: typeof components.UploadV3
29
29
  CiUploadV4: typeof components.UploadV4
30
+ CiUploadV5: typeof components.UploadV5
30
31
 
31
32
  CiSelect: typeof components.Select
32
33
  CiSelectTable: typeof components.SelectTable
@@ -0,0 +1,4 @@
1
+ import _UploadV5 from '../uploadV5.vue'
2
+ import { withInstall } from '../../utils/index'
3
+ export const UploadV5 = withInstall(_UploadV5)
4
+ export default UploadV5
@@ -0,0 +1,470 @@
1
+ <!-- /**
2
+ * @module uploadV4
3
+ * @author : 卖女孩的小火柴
4
+ * !description : 其它入库 导入组件
5
+ * @version : 1.0.0
6
+ * @since : 创建时间 2025-08-14 14:36:38
7
+ */ -->
8
+
9
+ <template>
10
+ <el-popover
11
+ placement="bottom"
12
+ :width="300"
13
+ :trigger="props.otherConfig?.trigger || 'hover'"
14
+ :visible="visible"
15
+ >
16
+ <el-upload
17
+ ref="upload"
18
+ class="upload-demo"
19
+ :action="uploadUrl"
20
+ :limit="mylimit || 1"
21
+ :on-exceed="handleExceed"
22
+ :auto-upload="false"
23
+ :on-success="onSuccess"
24
+ :on-error="onError"
25
+ :on-change="handleChange"
26
+ :on-remove="handleRemove"
27
+ :data="datas"
28
+ :multiple="mymultiple || false"
29
+ v-model:file-list="fileList"
30
+ >
31
+ <template #trigger>
32
+ <el-button size="small" type="primary" style="width: 100%" plain>
33
+ {{ t('fileRelated.selectFile') }}
34
+ </el-button>
35
+ </template>
36
+ <el-button
37
+ size="small"
38
+ @click="formwork"
39
+ style="float: left; margin: 0 12px 0 0; width: 95px"
40
+ v-if="url"
41
+ >
42
+ {{ t('fileRelated.downloadTemplate') }}
43
+ </el-button>
44
+ </el-upload>
45
+
46
+ <div class="slot" style="display: flex; flex-direction: column; align-items: flex-end">
47
+ <div style="width: 100%; margin: 4px 2px" v-if="ifShowAffiliation">
48
+ <el-select-v2
49
+ size="small"
50
+ v-model="affiliationAll"
51
+ filterable
52
+ :options="affiliationOptions"
53
+ :placeholder="t('fileRelated.selectCompany')"
54
+ style="width: 100%; margin-right: 5px"
55
+ clearable
56
+ @change="changeAll"
57
+ />
58
+ </div>
59
+ <div style="width: 100%; margin: 4px 2px" v-if="ifShowWarehouse">
60
+ <el-select-v2
61
+ size="small"
62
+ v-model="warehouseAll"
63
+ filterable
64
+ :options="warehouseOptions"
65
+ :placeholder="t('fileRelated.selectWarehouse')"
66
+ style="width: 100%; margin-right: 5px"
67
+ clearable
68
+ @change="changeWarehouseAll"
69
+ />
70
+ </div>
71
+ <!-- 添加一个插槽 -->
72
+ <slot></slot>
73
+ <div>
74
+ <el-button size="small" type="primary" @click="submitUpload" style="flex: 2">
75
+ {{ t('fileRelated.upload') }}
76
+ </el-button>
77
+ </div>
78
+ </div>
79
+
80
+ <template #reference>
81
+ <el-button
82
+ :type="exporLoading ? 'danger' : 'success'"
83
+ @click="visible = !visible"
84
+ :size="props.otherConfig?.size || 'small'"
85
+ :loading="exporLoading"
86
+ >
87
+ {{ props.title || t('fileRelated.attachmentUpload') }}
88
+ </el-button>
89
+ </template>
90
+ </el-popover>
91
+ </template>
92
+
93
+ <script setup lang="ts">
94
+ defineOptions({ name: 'ci-uploadV5' })
95
+
96
+ // 定义一个函数,用于处理字符串
97
+
98
+ const setFilePath = (arr: string[], url?: string) => {
99
+ // console.log('重新渲染数据', arr);
100
+ if (arr && arr.length > 0) {
101
+ let newArr: { name: string; oldName: string }[] = []
102
+ arr.forEach((item, i) => {
103
+ let segments = item.split('.')
104
+ let parts = segments[0].split('/') // 获取每名称
105
+ let name = parts[parts.length - 1] + '.' + segments[segments.length - 1]
106
+ let oldName = url ? url + item : item //原来的名称
107
+ // let url = segments[0] + '.' + segments[segments.length - 1]
108
+ newArr.push({ name, oldName })
109
+ })
110
+ return newArr
111
+ } else {
112
+ return [] // 如果数组为空,则返回空数组
113
+ }
114
+ }
115
+
116
+ // 将路径处理成附件的参数
117
+ const fileArr = (url: string, pathArr: string[]) => {
118
+ if (pathArr && pathArr.length > 0) {
119
+ let objArr: any = []
120
+ if (pathArr.length > 0) {
121
+ pathArr.map((item: any) => {
122
+ objArr.push({
123
+ name: item.name,
124
+ oldName: item.oldName,
125
+ url: url + item.oldName
126
+ })
127
+ })
128
+ return objArr
129
+ } else {
130
+ return []
131
+ }
132
+ }
133
+ }
134
+ import t from '../utils/lang/index'
135
+ import ajaxBox from '../utils/ajaxBox'
136
+ import { getAffiliationOptions, getWarehouseList, axios } from '../utils/getAffiliationOptions.ts'
137
+ import type { AxiosRequestConfig } from 'axios'
138
+ import { computed, onMounted, ref } from 'vue'
139
+ // import t from '@/views/MaterialWarehouse/lang'
140
+ // import ajaxBox from '@/views/MaterialWarehouse/utils/ajaxBox'
141
+ // import { getAffiliationOptions, getWarehouseList, axios } from '@/views/MaterialWarehouse/utils/getAffiliationOptions.ts'
142
+
143
+ import type {
144
+ UploadFile,
145
+ UploadFiles,
146
+ UploadInstance,
147
+ UploadProps,
148
+ UploadUserFile
149
+ } from 'element-plus'
150
+ import {
151
+ ElButton,
152
+ ElLoading,
153
+ ElMessage,
154
+ ElPopover,
155
+ ElSelectV2,
156
+ ElUpload,
157
+ genFileId,
158
+ UploadRawFile
159
+ } from 'element-plus'
160
+
161
+ const upload = ref<UploadInstance>()
162
+ const exporLoading = ref(false)
163
+ const visible = ref(false)
164
+ const affiliationAll = ref() // 选择的归属公司
165
+ const warehouseAll = ref() // 选择的仓库
166
+ const affiliationOptions = ref<any[]>([]) // 获取归属公司列表数据
167
+ const warehouseOptions = ref<any[]>([]) // 获取仓库列表数据
168
+
169
+ interface Props {
170
+ url?: string // 上传和下载模板的接口(当需要将附件传递回父组件时不需要传递此属性)
171
+ uploadUrl?: string // 上传附件的接口
172
+ parameter?: Object // 模板下载的时候请求需要携带的参数:{state: 1}
173
+ data?: any //上传携带的其他数据对象:{userId: 1, userName: '张三'}
174
+ title?: string // 上传按钮的名称
175
+ multiple?: boolean // 是否支持多文件
176
+ limit?: number // 最大文件数量
177
+ ifShowAffiliation?: boolean // 是否显示归属公司
178
+ requiredAffiliation?: boolean // 是否必选归属公司
179
+ ifShowWarehouse?: boolean // 是否显示仓库
180
+ requiredWarehouse?: boolean // 是否必选仓库
181
+ ifDefaultAffiliation?: boolean // 是否默认选中归属工厂默认值true
182
+ defaultAffiliationOrgid?: string // 默认选中归属工厂的 orgid(默认值当前登陆账号的单位)
183
+ filePath?: UploadFile[] //UploadRawFile[] // 父组件传递的附件数据,用于显示附件列表和上传附件后传递给父组件附件数据
184
+ RowIndex?: number // 父组件传递的行索引,用于父组件中删除了附件找到对应的行(用于表格表单中上传附件)
185
+ templateName?: string //模板名称
186
+ timeOn?: boolean // 是否开启耗时任务 默认不开启
187
+ // 其他的一些配置:请求的baseurl地址,有耗时任务的时候耗时任务的配置,模板下载的一些配置等
188
+ otherConfig: {
189
+ size?: 'large' | 'default' | 'small' // 按钮大小
190
+ trigger?: 'click' | 'focus' | 'hover' | 'contextmenu' // 按钮触发方式 默认 hover
191
+ baseUrl?: string // 上请求的baseurl地址
192
+ datakey: string // 耗时请求的参数key值
193
+ // 耗时任务的配置
194
+ timeConfig: {
195
+ url: string // 查询耗时任务地址
196
+ method: 'put' | 'post' | 'get' | 'PUT' | 'POST' | 'GET'
197
+ data?: object // 可选属性
198
+ params?: object // 可选属性
199
+ }
200
+ }
201
+ }
202
+ const props = defineProps<Props>()
203
+
204
+ // 默认值:是否显示归属公司
205
+ const ifShowAffiliation = computed(() => {
206
+ return props.ifShowAffiliation || true
207
+ })
208
+ // 默认值:是否显示仓库
209
+ const ifShowWarehouse = computed(() => {
210
+ return props.ifShowWarehouse || false
211
+ })
212
+ // 默认值:是否必选归属公司
213
+ const requiredAffiliation = computed(() => {
214
+ return props.requiredAffiliation || false
215
+ })
216
+ // 默认值:是否必选仓库
217
+ const requiredWarehouse = computed(() => {
218
+ return props.requiredWarehouse || false
219
+ })
220
+
221
+ // 是否默认选中归属工厂(默认值true)
222
+ const ifDefaultAffiliation = computed(() => {
223
+ return props.ifDefaultAffiliation || true
224
+ })
225
+
226
+ // 获取本地缓存中当前登陆账号的公司
227
+ const raw = localStorage.getItem('UserData')
228
+ const UserData = raw ? JSON.parse(raw) : {}
229
+ const defaultAffiliationOrgid = computed(() => {
230
+ return props.defaultAffiliationOrgid || UserData?.resOrgId // 默认登陆账号的单位
231
+ })
232
+
233
+ const emits = defineEmits<{
234
+ (e: 'reloadTable'): void // 组件中上传附件后刷新父组件表格数据方法
235
+ (e: 'getFile', files: UploadFiles, file?: UploadFile, rowindex?: number): void // 编辑表单的时候回显附件用到
236
+ (e: 'update:file', files: UploadFiles): void // 编辑表单的时候回显附件用到
237
+ }>()
238
+ console.log('附件props: ', props)
239
+ const datas: any = ref(props.data)
240
+ const mymultiple = ref<boolean>(props.multiple)
241
+ const mylimit = ref<number>((props.limit as number) || 1)
242
+ const myfilePath = ref<any>(props.filePath || [])
243
+ console.log('myfilePath: ', props.filePath)
244
+
245
+ const changeAll = (val: string) => {
246
+ datas.value.factory_affiliation_id = val
247
+ datas.value.factory_affiliation_name = affiliationOptions.value.find(
248
+ (item: any) => item.value === val
249
+ )?.label
250
+ }
251
+
252
+ const changeWarehouseAll = (val: string) => {
253
+ datas.value.warehouse_id = val
254
+ datas.value.warehouse_name = warehouseOptions.value.find((item: any) => item.value === val)?.label
255
+
256
+ console.log('%c Line:236 🍐 datas.value', 'color:#ea7e5c', datas.value)
257
+ }
258
+
259
+ // 对数组中的每个字符串应用处理函数
260
+ let pathArr = setFilePath(myfilePath.value)
261
+
262
+ // 打印处理后的数组
263
+ // 将父组件中传递过来的名称,处理成el-upload需要的格式
264
+ let pathUrlArr = fileArr(import.meta.env.VITE_BASE_URL9999, pathArr)
265
+ console.log('fileObj(): ', pathUrlArr)
266
+ const fileList = ref<UploadUserFile[]>(pathUrlArr)
267
+ console.log('fileList: ', fileList.value)
268
+
269
+ //当超出限制时,执行的钩子函数
270
+ const handleExceed: UploadProps['onExceed'] = (files) => {
271
+ console.log('%c Line:177 🥝 files', 'color:#e41a6a', files)
272
+
273
+ if (mylimit?.value === 1) {
274
+ upload.value!.clearFiles()
275
+ const file = files[0] as UploadRawFile
276
+ file.uid = genFileId()
277
+ upload.value!.handleStart(file)
278
+ }
279
+ if (mylimit?.value > 1) {
280
+ console.log('超出限制: ', files)
281
+ ElMessage.warning(
282
+ `${t('fileRelated.exceedFiles')} ${mylimit?.value} ${t('fileRelated.reselect')}`
283
+ )
284
+ }
285
+ }
286
+
287
+ // 文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用
288
+ const handleChange = (file: any, fileLists: any) => {
289
+ if (!props.url) {
290
+ emits('getFile', fileLists) //将选中的文件传递回父组件
291
+ emits('update:file', fileLists) //同步父组件绑定的附件字段,以便父组件提交表单的时候一起将附件提交
292
+ }
293
+ }
294
+ // 文件列表删除时
295
+ const handleRemove: UploadProps['onRemove'] = (file, fileList) => {
296
+ console.log('file: ', file)
297
+ console.log('fileList: ', fileList)
298
+ // 如果没有url时 在删除的时候将文件流同步回父组件
299
+ if (!props.url) {
300
+ emits('getFile', fileList, file, props.RowIndex)
301
+ emits('update:file', fileList)
302
+ }
303
+ }
304
+ //上传文件
305
+ const submitUpload = () => {
306
+ if (!fileList.value || !fileList.value.length) {
307
+ return ElMessage.warning(t('fileRelated.pleaseFile'))
308
+ }
309
+
310
+ // 判断是否归属公司必选并且选择了值
311
+ console.log(
312
+ '%c Line:312 🍤 判断',
313
+ 'color:#33a5ff',
314
+ requiredAffiliation.value && !datas.value.factory_affiliation_id,
315
+ requiredAffiliation.value,
316
+ datas.value.factory_affiliation_id
317
+ )
318
+ console.log(fileList.value.length)
319
+ console.log(
320
+ '%c Line:312 🍤 判断',
321
+ 'color:#33a5ff',
322
+ requiredAffiliation.value && !datas.value.factory_affiliation_id,
323
+ requiredAffiliation.value,
324
+ datas.value.factory_affiliation_id
325
+ )
326
+ console.log('%c Line:312 🍎 选中归属公司', 'color:#ed9ec7', datas.value.factory_affiliation_id)
327
+ console.log('%c Line:319 🍔 必填', 'color:#93c0a4', requiredAffiliation.value)
328
+ if (!datas.value.factory_affiliation_id && requiredAffiliation.value) {
329
+ return ElMessage.warning(t('fileRelated.selectCompany'))
330
+ }
331
+ // 判断 出库是否必填 并且选择了值
332
+ if (!datas.value.warehouse_id && requiredWarehouse.value) {
333
+ return ElMessage.warning(t('fileRelated.pleaseSelectWarehouse'))
334
+ }
335
+ // exporLoading.value = ElLoading.service({ text: t('fileRelated.importing') })
336
+ exporLoading.value = true
337
+ console.log('upload.value', upload.value)
338
+ upload.value!.submit()
339
+ visible.value = false
340
+ }
341
+ //文件上传成功回调
342
+ const onSuccess = async (res: any, file: any, fileList: any) => {
343
+ console.log('fileList: ', fileList)
344
+ console.log('file: ', file)
345
+ console.log('上传成功回调: ', res)
346
+ // exporLoading.value.close() // 关闭加载动画
347
+ if (res.code !== 200) {
348
+ upload.value!.clearFiles() // 清空文件列表
349
+ // exporLoading.value.close() // 关闭加载动画
350
+ exporLoading.value = false
351
+ return ElMessage.warning(res.msg)
352
+ }
353
+
354
+ // 判断是否要走耗时逻辑
355
+ if (!props.timeOn || !res.data) {
356
+ upload.value!.clearFiles() // 清空文件列表
357
+ visible.value = false // 关闭上传面板
358
+ // exporLoading.value.close() // 关闭加载动画
359
+ exporLoading.value = false
360
+ ElMessage.success(res.msg)
361
+ emits('reloadTable')
362
+ return
363
+ }
364
+
365
+ // 处理耗时请求的参数
366
+ let datas = {}
367
+ datas[props.otherConfig?.datakey] = res.data.task_id
368
+ // 耗时轮训
369
+ const data = await askForTask(datas)
370
+ console.log('data: ', data)
371
+ if (data.code === 200) {
372
+ // fileList.value.length = 0 // 清空文件列表
373
+ upload.value!.clearFiles() // 清空文件列表
374
+ visible.value = false // 关闭上传面板
375
+ // exporLoading.value.close() // 关闭加载动画
376
+ exporLoading.value = false
377
+ ElMessage.success(data.msg)
378
+ emits('reloadTable')
379
+ } else if (data.code === 0) {
380
+ upload.value!.clearFiles() // 清空文件列表
381
+ exporLoading.value = false
382
+ ElMessage.error(data.msg || '导入失败')
383
+ // exporLoading.value.close() // 关闭加载动画
384
+ } else {
385
+ ElMessage.error(data.msg || '请求超时或者其他错误,请联系管理员.')
386
+ }
387
+ }
388
+ //文件上传失败回调
389
+ const onError = (response: any, file: any, fileList: any) => {
390
+ console.log('上传失败回调: ', response)
391
+ ElMessage.error(file.name + t('fileRelated.uploadFailed'))
392
+ // fileList.value.length = 0 // 清空文件列表
393
+ upload.value!.clearFiles() // 清空文件列表
394
+ visible.value = false // 关闭上传面板
395
+ // exporLoading.value.close() // 关闭加载动画
396
+ exporLoading.value = false
397
+ }
398
+
399
+ // 耗时请求函数
400
+ const askForTask: (task_info: any) => Promise<any> = async (task_info: any) => {
401
+ // 处理父组件传递的配置
402
+ const axiosConfig: AxiosRequestConfig = {
403
+ ...props.otherConfig?.timeConfig
404
+ }
405
+ // 处理请求的参数
406
+ if (
407
+ props.otherConfig?.timeConfig?.method === 'get' ||
408
+ props.otherConfig?.timeConfig?.method === 'GET'
409
+ ) {
410
+ axiosConfig.params = {
411
+ ...props.otherConfig?.timeConfig.params,
412
+ ...task_info
413
+ }
414
+ } else {
415
+ axiosConfig.data = {
416
+ ...props.otherConfig?.timeConfig.data,
417
+ ...task_info
418
+ }
419
+ }
420
+ try {
421
+ const res = await axios(axiosConfig)
422
+ // 如果返回的code是50001 就继续轮询,直到返回的code不是50001
423
+ if (res.data.code === 50001)
424
+ return await new Promise((resolve) => {
425
+ setTimeout(() => resolve(askForTask(task_info)), 2000)
426
+ })
427
+ return res.data
428
+ } catch (error) {
429
+ console.error('Error fetching task:', error)
430
+ throw error
431
+ }
432
+ }
433
+
434
+ //下载模板
435
+ const formwork = () => {
436
+ const url = props.url as string
437
+ const params = props.parameter
438
+ ajaxBox.downFileFetchV2(url, params, {
439
+ method: 'GET',
440
+ fileName: props.templateName || t('fileRelated.template')
441
+ })
442
+ }
443
+
444
+ //选择框
445
+ onMounted(async () => {
446
+ if (props.url && ifShowAffiliation.value) {
447
+ affiliationOptions.value = await getAffiliationOptions()
448
+ if (props.data && ifShowWarehouse.value) {
449
+ warehouseOptions.value = await getWarehouseList({
450
+ storage_type: props.data?.storage_type || 'CAILIAO'
451
+ })
452
+ }
453
+ } else {
454
+ affiliationOptions.value = []
455
+ warehouseOptions.value = []
456
+ }
457
+
458
+ // 判断是否默认选中归属公司
459
+ if (ifDefaultAffiliation.value) {
460
+ affiliationAll.value = defaultAffiliationOrgid.value
461
+ datas.value.factory_affiliation_id = defaultAffiliationOrgid.value
462
+ }
463
+ })
464
+ </script>
465
+
466
+ <style scoped lang="scss">
467
+ :deep(.el-upload) {
468
+ width: calc(100% - 110px);
469
+ }
470
+ </style>
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ export * from './fileRelated/index/ciupload' // 导出附件上传组件
19
19
  export * from './fileRelated/index/ciuploadV2' // 导出附件上传v2组件
20
20
  export * from './fileRelated/index/ciuploadV3' // 导出附件上传v3组件
21
21
  export * from './fileRelated/index/ciuploadV4' // 导出附件上传v4组件
22
+ export * from './fileRelated/index/ciuploadV5' // 导出附件上传v5组件
22
23
 
23
24
  export * from './select' // 导出select组件
24
25
  export * from './selectTable' // 导出selectTable组件