ci-plus 1.7.6 → 1.7.8

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.7.8
5
+ 1、导入组件3中优化单选文件的时候覆盖文件逻辑
6
+ 1.7.7
7
+ 1、新增导入组件3(可以选择归属公司)
4
8
  1.7.6
5
9
  1、调整语言文件中翻译对象
6
10
  1.7.5
package/index.ts CHANGED
@@ -1,14 +1,14 @@
1
- import * as components from './src/index';
2
- export * from './src/index';
3
- import { App } from 'vue';
4
- import { default as Fn } from './src/utils';
1
+ import * as components from './src/index'
2
+ export * from './src/index'
3
+ import { App } from 'vue'
4
+ import { default as Fn } from './src/utils'
5
5
  export default {
6
6
  install: (app: App) => {
7
7
  // 注册所有组件
8
- console.log('注册所有ci-plus组件1.3.9: ');
8
+ console.log('注册所有ci-plus组件1.7.7: ', components)
9
9
  for (const c in components) {
10
- app.use(components[c]);
10
+ app.use(components[c])
11
11
  }
12
12
  },
13
- Fn,
14
- };
13
+ Fn
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ci-plus",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "ci组件库",
5
5
  "main": "./index.ts",
6
6
  "scripts": {
@@ -0,0 +1,4 @@
1
+ import _UploadV3 from '../uploadV3.vue'
2
+ import { withInstall } from '../../utils/index'
3
+ export const UploadV3 = withInstall(_UploadV3)
4
+ export default UploadV3
@@ -0,0 +1,360 @@
1
+ <template>
2
+ <el-popover
3
+ placement="bottom"
4
+ :width="300"
5
+ :trigger="props.otherConfig?.trigger || 'hover'"
6
+ :visible="visible"
7
+ >
8
+ <el-upload
9
+ ref="upload"
10
+ class="upload-demo"
11
+ :action="url + '_post/'"
12
+ :limit="mylimit || 1"
13
+ :on-exceed="handleExceed"
14
+ :auto-upload="false"
15
+ :on-success="onSuccess"
16
+ :on-error="onError"
17
+ :on-change="handleChange"
18
+ :on-remove="handleRemove"
19
+ :data="datas"
20
+ :multiple="mymultiple || false"
21
+ v-model:file-list="fileList"
22
+ >
23
+ <template #trigger>
24
+ <el-button size="small" type="primary" style="width: 100%" plain> 选择文件 </el-button>
25
+ </template>
26
+ <el-button
27
+ size="small"
28
+ @click="formwork"
29
+ style="float: left; margin: 0 12px 0 0; width: 95px"
30
+ v-if="url"
31
+ >
32
+ 下载模板
33
+ </el-button>
34
+ </el-upload>
35
+
36
+ <div style="width: 100%; display: flex" v-if="url">
37
+ <el-select-v2
38
+ size="small"
39
+ v-model="affiliationAll"
40
+ filterable
41
+ :options="affiliationOptions"
42
+ placeholder="选择归属公司"
43
+ style="width: 180px; margin-right: 5px"
44
+ clearable
45
+ @change="changeAll"
46
+ />
47
+ <el-button size="small" type="primary" @click="submitUpload" style="flex: 2">
48
+ 上传
49
+ </el-button>
50
+ </div>
51
+ <template #reference>
52
+ <el-button
53
+ type="success"
54
+ @click="visible = !visible"
55
+ :size="props.otherConfig?.size || 'small'"
56
+ >
57
+ {{ props.title || '附件上传' }}
58
+ </el-button>
59
+ </template>
60
+ </el-popover>
61
+ </template>
62
+
63
+ <script setup lang="ts">
64
+ defineOptions({ name: 'ci-uploadV3' })
65
+ // 定义一个函数,用于处理字符串
66
+ const setFilePath = (arr: string[], url?: string) => {
67
+ // console.log('重新渲染数据', arr);
68
+ if (arr && arr.length > 0) {
69
+ let newArr: { name: string; oldName: string }[] = []
70
+ arr.forEach((item, i) => {
71
+ let segments = item.split('.')
72
+ let parts = segments[0].split('/') // 获取每名称
73
+ let name = parts[parts.length - 1] + '.' + segments[segments.length - 1]
74
+ let oldName = url ? url + item : item //原来的名称
75
+ // let url = segments[0] + '.' + segments[segments.length - 1]
76
+ newArr.push({ name, oldName })
77
+ })
78
+ return newArr
79
+ } else {
80
+ return [] // 如果数组为空,则返回空数组
81
+ }
82
+ }
83
+
84
+ // 将路径处理成附件的参数
85
+ const fileArr = (url: string, pathArr: string[]) => {
86
+ if (pathArr && pathArr.length > 0) {
87
+ let objArr: any = []
88
+ if (pathArr.length > 0) {
89
+ pathArr.map((item: any) => {
90
+ objArr.push({
91
+ name: item.name,
92
+ oldName: item.oldName,
93
+ url: url + item.oldName
94
+ })
95
+ })
96
+ return objArr
97
+ } else {
98
+ return []
99
+ }
100
+ }
101
+ }
102
+
103
+ import type { AxiosRequestConfig } from 'axios';
104
+ import axios from 'axios';
105
+ import type {
106
+ UploadFile,
107
+ UploadFiles,
108
+ UploadInstance,
109
+ UploadProps,
110
+ UploadUserFile
111
+ } from 'element-plus';
112
+ import { ElButton, ElLoading, ElMessage, ElPopover, ElSelectV2, ElUpload, genFileId, UploadRawFile } from 'element-plus';
113
+ import { onMounted, ref } from 'vue';
114
+ import ajaxBox from '../utils/ajaxBox';
115
+ import getAffiliationOptions from '../utils/getAffiliationOptions.ts';
116
+ const upload = ref<UploadInstance>()
117
+ const exporLoading = ref()
118
+ const visible = ref(false)
119
+ const affiliationAll = ref()
120
+ const affiliationOptions = ref<any[]>([]) // 获取归属公司列表数据
121
+
122
+ interface Props {
123
+ url?: string // 上传和下载模板的接口(当需要将附件传递回父组件时不需要传递此属性)
124
+ parameter?: Object // 模板下载的时候请求需要携带的参数:{state: 1}
125
+ data?: Object //上传携带的其他数据对象:{userId: 1, userName: '张三'}
126
+ title?: string // 上传按钮的名称
127
+ multiple?: boolean // 是否支持多文件
128
+ limit?: number // 最大文件数量
129
+ filePath?: UploadFile[] //UploadRawFile[] // 父组件传递的附件数据,用于显示附件列表和上传附件后传递给父组件附件数据
130
+ RowIndex?: number // 父组件传递的行索引,用于父组件中删除了附件找到对应的行(用于表格表单中上传附件)
131
+ templateName?: string //模板名称
132
+ timeOn?: boolean // 是否开启耗时任务 默认不开启
133
+ // 其他的一些配置:请求的baseurl地址,有耗时任务的时候耗时任务的配置,模板下载的一些配置等
134
+ otherConfig: {
135
+ size?: 'large' | 'default' | 'small' // 按钮大小
136
+ trigger?: 'click' | 'focus' | 'hover' | 'contextmenu' // 按钮触发方式 默认 hover
137
+ baseUrl?: string // 上请求的baseurl地址
138
+ datakey: string // 耗时请求的参数key值
139
+ // 耗时任务的配置
140
+ timeConfig: {
141
+ url: string
142
+ method: 'put' | 'post' | 'get' | 'PUT' | 'POST' | 'GET'
143
+ data?: object // 可选属性
144
+ params?: object // 可选属性
145
+ }
146
+ }
147
+ }
148
+ const props = defineProps<Props>()
149
+ const emits = defineEmits<{
150
+ (e: 'reloadTable'): void // 组件中上传附件后刷新父组件表格数据方法
151
+ (e: 'getFile', files: UploadFiles, file?: UploadFile, rowindex?: number): void // 编辑表单的时候回显附件用到
152
+ (e: 'update:file', files: UploadFiles): void // 编辑表单的时候回显附件用到
153
+ }>()
154
+ console.log('附件props: ', props)
155
+ const datas: any = ref(props.data)
156
+ const mymultiple = ref<boolean>(props.multiple)
157
+ const mylimit = ref<number>(props.limit as number ||1)
158
+ const myfilePath = ref<any>(props.filePath || [])
159
+ console.log('myfilePath: ', props.filePath)
160
+
161
+ const changeAll = (val: string) => {
162
+ datas.value.factory_affiliation_id = val
163
+ }
164
+
165
+ // 对数组中的每个字符串应用处理函数
166
+ let pathArr = setFilePath(myfilePath.value)
167
+
168
+ // 打印处理后的数组
169
+ // 将父组件中传递过来的名称,处理成el-upload需要的格式
170
+ let pathUrlArr = fileArr(import.meta.env.VITE_BASE_URL9999, pathArr)
171
+ console.log('fileObj(): ', pathUrlArr)
172
+ const fileList = ref<UploadUserFile[]>(pathUrlArr)
173
+ console.log('fileList: ', fileList.value)
174
+
175
+ //当超出限制时,执行的钩子函数
176
+ const handleExceed: UploadProps['onExceed'] = (files) => {
177
+ console.log("%c Line:177 🥝 files", "color:#e41a6a", files);
178
+
179
+ if(mylimit?.value === 1){
180
+ upload.value!.clearFiles()
181
+ const file = files[0] as UploadRawFile
182
+ file.uid = genFileId()
183
+ upload.value!.handleStart(file)
184
+ }
185
+ if( mylimit?.value > 1){
186
+ console.log('超出限制: ', files)
187
+ ElMessage.warning(`超出最大文件数:${mylimit?.value}个文件,请重新选择`)
188
+ }
189
+ }
190
+
191
+ // 文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用
192
+ const handleChange = (file: any, fileLists: any) => {
193
+ if (!props.url) {
194
+ emits('getFile', fileLists) //将选中的文件传递回父组件
195
+ emits('update:file', fileLists) //同步父组件绑定的附件字段,以便父组件提交表单的时候一起将附件提交
196
+ }
197
+ }
198
+ // 文件列表删除时
199
+ const handleRemove: UploadProps['onRemove'] = (file, fileList) => {
200
+ console.log('file: ', file)
201
+ console.log('fileList: ', fileList)
202
+ // 如果没有url时 在删除的时候将文件流同步回父组件
203
+ if (!props.url) {
204
+ emits('getFile', fileList, file, props.RowIndex)
205
+ emits('update:file', fileList)
206
+ }
207
+ }
208
+ //上传文件
209
+ const submitUpload = () => {
210
+ console.log(fileList.value.length)
211
+ if (!fileList.value.length) return ElMessage.warning('请选择文件后在上传12!')
212
+ exporLoading.value = ElLoading.service({ text: '导入中...' })
213
+ console.log('upload.value', upload.value)
214
+ upload.value!.submit()
215
+ visible.value = false
216
+ }
217
+ //文件上传成功回调
218
+ const onSuccess = async (res: any, file: any, fileList: any) => {
219
+ console.log('fileList: ', fileList)
220
+ console.log('file: ', file)
221
+ console.log('上传成功回调: ', res)
222
+ // exporLoading.value.close() // 关闭加载动画
223
+ if (res.code !== 200) {
224
+ upload.value!.clearFiles() // 清空文件列表
225
+ exporLoading.value.close() // 关闭加载动画
226
+ return ElMessage.warning(res.msg)
227
+ }
228
+
229
+ // 判断是否要走耗时逻辑
230
+ if (!props.timeOn || !res.data) {
231
+ upload.value!.clearFiles() // 清空文件列表
232
+ visible.value = false // 关闭上传面板
233
+ exporLoading.value.close() // 关闭加载动画
234
+ ElMessage.success(res.msg)
235
+ emits('reloadTable')
236
+ return
237
+ }
238
+
239
+ // 处理耗时请求的参数
240
+ let datas = {}
241
+ datas[props.otherConfig?.datakey] = res.data.task_id
242
+ // 耗时轮训
243
+ const data = await askForTask(datas)
244
+ console.log('data: ', data)
245
+ if (data.code === 200) {
246
+ // fileList.value.length = 0 // 清空文件列表
247
+ upload.value!.clearFiles() // 清空文件列表
248
+ visible.value = false // 关闭上传面板
249
+ exporLoading.value.close() // 关闭加载动画
250
+ ElMessage.success(data.msg)
251
+ emits('reloadTable')
252
+ } else if (data.code === 0) {
253
+ exporLoading.value.close() // 关闭加载动画
254
+ ElMessage.success(data.msg || '导入失败')
255
+ } else {
256
+ ElMessage.success(data.msg || '请求超时或者其他错误,请联系管理员.')
257
+ }
258
+ }
259
+ //文件上传失败回调
260
+ const onError = (response: any, file: any, fileList: any) => {
261
+ console.log('上传失败回调: ', response)
262
+ ElMessage.error(file.name + '上传失败')
263
+ // fileList.value.length = 0 // 清空文件列表
264
+ upload.value!.clearFiles() // 清空文件列表
265
+ visible.value = false // 关闭上传面板
266
+ exporLoading.value.close() // 关闭加载动画
267
+ }
268
+
269
+ // 耗时请求函数
270
+ const askForTask: (task_info: any) => Promise<any> = async (task_info: any) => {
271
+ // 处理父组件传递的配置
272
+ const axiosConfig: AxiosRequestConfig = {
273
+ ...props.otherConfig?.timeConfig
274
+ }
275
+ // 处理请求的参数
276
+ if (
277
+ props.otherConfig?.timeConfig?.method === 'get' ||
278
+ props.otherConfig?.timeConfig?.method === 'GET'
279
+ ) {
280
+ axiosConfig.params = {
281
+ ...props.otherConfig?.timeConfig.params,
282
+ ...task_info
283
+ }
284
+ } else {
285
+ axiosConfig.data = {
286
+ ...props.otherConfig?.timeConfig.data,
287
+ ...task_info
288
+ }
289
+ }
290
+ try {
291
+ const res = await axios(axiosConfig)
292
+ // 如果返回的code是50001 就继续轮询,直到返回的code不是50001
293
+ if (res.data.code === 50001)
294
+ return await new Promise((resolve) => {
295
+ setTimeout(() => resolve(askForTask(task_info)), 2000)
296
+ })
297
+ return res.data
298
+ } catch (error) {
299
+ console.error('Error fetching task:', error)
300
+ throw error
301
+ }
302
+ }
303
+
304
+ //下载模板
305
+ const formwork = () => {
306
+ const url = props.url + '_get/'
307
+ const params = props.parameter
308
+ ajaxBox.downFileFetchV2(url, params, {
309
+ method: 'GET',
310
+ fileName: props.templateName || '模板.xlsx'
311
+ })
312
+ }
313
+
314
+ //选择框
315
+ onMounted(async () => {
316
+ affiliationOptions.value = await getAffiliationOptions()
317
+ })
318
+
319
+ // const getAffiliationOptions = async (
320
+ // list?: any[],
321
+ // keys: string[] = ['label', 'value'],
322
+ // val: string[] = ['name', 'id'],
323
+ // ) => {
324
+ // let url = produceModule + 'company_optional_scope_get/'
325
+ // let options: { [key: string]: any }[] = []
326
+ // try {
327
+ // const res = await axios.get(url)
328
+ // console.log('%c Line:360 🍊 res', 'color:#7f2b82', res)
329
+ // if (
330
+ // res.status === 200 && res.data.code === 200 &&
331
+ // Array.isArray(res.data?.data) &&
332
+ // res.data.data.length > 0
333
+ // ) {
334
+ // res.data.data.forEach((item: AffiliationRES) => {
335
+ // const obj: { [key: string]: any } = {}
336
+ // keys.forEach((key, index) => {
337
+ // const valueKey = val[index]
338
+ // obj[key] = item[valueKey as keyof AffiliationRES]
339
+ // })
340
+ // options.push(obj)
341
+ // })
342
+ // } else {
343
+ // console.error('请求失败:', res.data.msg)
344
+ // options = []
345
+ // }
346
+ // } catch (error) {
347
+ // console.error('请求失败:', error)
348
+ // options = []
349
+ // }
350
+ // console.log('%c Line:1338 🥝 result', 'color:#ea7e5c', options)
351
+ // list = options
352
+ // return options
353
+ // }
354
+ </script>
355
+
356
+ <style scoped lang="scss">
357
+ :deep(.el-upload) {
358
+ width: calc(100% - 110px);
359
+ }
360
+ </style>
package/src/index.ts CHANGED
@@ -1,23 +1,24 @@
1
- export * from './button';
2
- export * from './icon';
3
- export * from './buttons';
4
- export * from './dailog';
5
- export * from './ccapp';
6
- export * from './svgIcon';// svg图标
7
- export * from './selectSuffix';
8
- export * from './sortableTable/index/headButtons'; // 导出排序表头按钮
9
- export * from './sortableTable/index/headerInput'; // 导出筛选面板
10
- export * from './sortableTable/index/sortableTable'; // 导出排序表格
11
- export * from './sortableTable/index/sortableTableDialog'; // 导出表排序组件
12
- export * from './sortableTable/index/sortableTableColumnCell'; // 导出表列组件
1
+ export * from './button'
2
+ export * from './icon'
3
+ export * from './buttons'
4
+ export * from './dailog'
5
+ export * from './ccapp'
6
+ export * from './svgIcon' // svg图标
7
+ export * from './selectSuffix'
8
+ export * from './sortableTable/index/headButtons' // 导出排序表头按钮
9
+ export * from './sortableTable/index/headerInput' // 导出筛选面板
10
+ export * from './sortableTable/index/sortableTable' // 导出排序表格
11
+ export * from './sortableTable/index/sortableTableDialog' // 导出表排序组件
12
+ export * from './sortableTable/index/sortableTableColumnCell' // 导出表列组件
13
13
 
14
- export * from './identificationCard'; // 导出标识卡条形码模板组件
15
- export * from './identificationCard/qrcode'; // 导出标识卡二维码模板组件
14
+ export * from './identificationCard' // 导出标识卡条形码模板组件
15
+ export * from './identificationCard/qrcode' // 导出标识卡二维码模板组件
16
16
 
17
- export * from './fileRelated/index/ciseeFile'; // 导出附件查看组件
18
- export * from './fileRelated/index/ciupload'; // 导出附件上传组件
19
- export * from './fileRelated/index/ciuploadV2'; // 导出附件上传v2组件
17
+ export * from './fileRelated/index/ciseeFile' // 导出附件查看组件
18
+ export * from './fileRelated/index/ciupload' // 导出附件上传组件
19
+ export * from './fileRelated/index/ciuploadV2' // 导出附件上传v2组件
20
+ export * from './fileRelated/index/ciuploadV3' // 导出附件上传v3组件
20
21
 
21
- export * from './select'; // 导出select组件
22
- export * from './selectTable'; // 导出selectTable组件
23
- export * from './queryCondition'; // 导出queryCondition组件
22
+ export * from './select' // 导出select组件
23
+ export * from './selectTable' // 导出selectTable组件
24
+ export * from './queryCondition' // 导出queryCondition组件
@@ -0,0 +1,67 @@
1
+ import apis from './baseApi'
2
+ import axios from 'axios'
3
+ const { produceModule } = apis
4
+
5
+ interface AffiliationRES {
6
+ id: string // 归属公司 id
7
+ name: string // 归属公司 名称
8
+ parentId: string // 归属公司 父级id
9
+ type: number // 归属公司 类型
10
+ del: string // 删除状态
11
+ createdId: string // 创建人id
12
+ createdDate: string // 创建时间
13
+ orgCode: string // 归属公司 编码
14
+ treePath: string // 归属公司 路径
15
+ updatedId?: any // 修改人id
16
+ updatedDate?: any // 修改时间
17
+ version?: any // 版本
18
+ sortNum?: any
19
+ attribute?: any
20
+ datasourceCode: string
21
+ platform?: any
22
+ platformTxt?: any
23
+ sector?: any
24
+ sectorTxt?: any
25
+ area?: any
26
+ areaTxt?: any
27
+ abbreviation?: any
28
+ superOrgId?: any
29
+ }
30
+ const getAffiliationOptions = async (
31
+ list?: any[],
32
+ keys: string[] = ['label', 'value'],
33
+ val: string[] = ['name', 'id']
34
+ ) => {
35
+ let url = produceModule + 'company_optional_scope_get/'
36
+ let options: { [key: string]: any }[] = []
37
+ try {
38
+ const res = await axios.get(url)
39
+ console.log('%c Line:360 🍊 res', 'color:#7f2b82', res)
40
+ if (
41
+ res.status === 200 &&
42
+ res.data.code === 200 &&
43
+ Array.isArray(res.data?.data) &&
44
+ res.data.data.length > 0
45
+ ) {
46
+ res.data.data.forEach((item: AffiliationRES) => {
47
+ const obj: { [key: string]: any } = {}
48
+ keys.forEach((key, index) => {
49
+ const valueKey = val[index]
50
+ obj[key] = item[valueKey as keyof AffiliationRES]
51
+ })
52
+ options.push(obj)
53
+ })
54
+ } else {
55
+ console.error('请求失败:', res.data.msg)
56
+ options = []
57
+ }
58
+ } catch (error) {
59
+ console.error('请求失败:', error)
60
+ options = []
61
+ }
62
+ console.log('%c Line:1338 🥝 result', 'color:#ea7e5c', options)
63
+ list = options
64
+ return options
65
+ }
66
+
67
+ export default getAffiliationOptions
@@ -8,17 +8,18 @@ import apis from './baseApi'
8
8
  import { setDate, setDateTime } from './Dayjs'
9
9
  import dayjs from './Dayjs'
10
10
  import ajaxBox from './ajaxBox' // 处理文件下载方法
11
- import t from './lang/index' // 中英文切换
11
+ import getAffiliationOptions from './getAffiliationOptions' // 处理文件下载方法
12
12
 
13
- // 导出 cardPrint 和 apis
14
- export default {
15
- apis,
13
+ let func = {
16
14
  cardPrint,
17
15
  setCardList,
18
16
  withInstall,
19
- dayjs,
20
17
  setDate,
21
18
  setDateTime,
22
- ajaxBox,
23
- t
19
+ getAffiliationOptions,
20
+ apis,
21
+ dayjs,
22
+ ajaxBox
24
23
  }
24
+ // 导出 所有方法
25
+ export default func