cnhis-design-vue 3.0.9 → 3.1.2

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.
@@ -1,6 +1,7 @@
1
1
  <script lang="tsx">
2
2
  import { defineComponent, ref, reactive } from 'vue'
3
3
  import { NSelect } from 'naive-ui'
4
+ import vexutils from '@/utils/vexutils.js'
4
5
 
5
6
  export default defineComponent({
6
7
  name: 'EditSelect',
@@ -26,8 +27,12 @@ export default defineComponent({
26
27
  setup (props, { attrs, slots, emit }) {
27
28
 
28
29
  const state = reactive({
29
- options: [] as any
30
+ options: [] as any,
31
+ loading: false,
32
+ keyword: '',
33
+ config: {} as any
30
34
  })
35
+
31
36
  const setOptions = async () => {
32
37
  if (props.col.options) {
33
38
  state.options = JSON.parse(JSON.stringify(props.col.options))
@@ -35,29 +40,52 @@ export default defineComponent({
35
40
  // 此处需要缓存第一次请求到的options,不需要每次都请求,
36
41
  // 此处的row参数应当是selectTable的row
37
42
  const optionsName = `${props.col.columnName}_options`
38
- state.options = props.row[optionsName] || await props.col.queryOptions()
39
- if (!props.row[optionsName]) {
40
- emit('setOptions', state.options)
43
+ const obj = {
44
+ keyword: state.keyword,
45
+ row: props.row,
46
+ column: props.col,
47
+ index: props.index
41
48
  }
49
+ // state.options = props.row[optionsName] || await props.col.queryOptions(obj)
50
+ state.options = await props.col.queryOptions(obj)
51
+ state.loading = false
52
+ // if (!props.row[optionsName]) {
53
+ emit('setOptions', state.options)
54
+ // }
42
55
  }
43
56
  }
44
-
45
- setOptions()
46
-
57
+
58
+ let selectSearch = (value: string) => {
59
+ state.keyword = value
60
+ state.loading = true
61
+ setOptions()
62
+ }
63
+ selectSearch = vexutils.debounce(selectSearch, 800)
47
64
  const onUpdateValue = (value: any[] | string | number | null) => {
48
65
  emit('formChange', { value, row: props.row, column: props.col, index: props.index })
49
66
  }
50
67
 
51
- console.log(attrs)
68
+ const init = () => {
69
+ if (props.col.options) {
70
+ setOptions()
71
+ } else {
72
+ state.config.remote = true
73
+ state.config.onSearch = selectSearch
74
+ // 初始化搜索
75
+ selectSearch('')
76
+ }
77
+ }
78
+ init()
52
79
  return () => [
53
80
  <NSelect
54
81
  {...attrs}
82
+ {...state.config}
55
83
  options={state.options}
56
84
  consistentMenuWidth={false}
57
85
  clearable
58
86
  filterable
59
- to={false}
60
87
  placeholder="请选择"
88
+ loading={state.loading}
61
89
  onUpdateValue={onUpdateValue}
62
90
  />
63
91
  ]
@@ -110,12 +110,11 @@ export const useEdit = (props: any, state: any, emit: any, xGrid: any) => {
110
110
  return params.row[item.formatMap.label]
111
111
  }
112
112
  if (item.options) {
113
- return item.options.find((v: any) => v.value == value)?.label || ''
113
+ return item.options.find((v: any) => v.value == value)?.label || value || ''
114
114
  }
115
115
  if (item.queryOptions) {
116
- return (params.row[`${item.columnName}_options`]?.find((v: any) => v.value === value)?.label) || ''
116
+ return (params.row[`${item.columnName}_options`]?.find((v: any) => v.value === value)?.label) || value || ''
117
117
  }
118
- return value
119
118
  }
120
119
  return value
121
120
  }
@@ -1,45 +1,46 @@
1
1
  <template>
2
- <span @click="handleClickWrap">
3
- <NDropdown
4
- placement="bottom-start"
5
- :show="state.visible"
6
- @clickoutside="handleClickOutside"
7
- :options="options"
8
- @select="handleSelect"
2
+ <n-dropdown
3
+ class="rowFoldHideBtnList-dropdown"
4
+ placement="bottom-start"
5
+ trigger="click"
6
+ :show="state.visible"
7
+ @clickoutside="handleClickOutside"
8
+ :options="options"
9
+ @select="handleSelect"
10
+ :render-label="renderLabel"
11
+ >
12
+ <slot
13
+ name="button"
14
+ :handleClickPrintBtn="handleClickBtn"
15
+ :printSpinning="state.spinning"
16
+ :printbtnText="btnText"
17
+ :printVisible="state.visible"
9
18
  >
10
- <slot
11
- name="button"
12
- :handleClickPrintBtn="handleClickBtn"
13
- :printSpinning="state.spinning"
14
- :printbtnText="btnText"
15
- :printVisible="state.visible"
16
- >
17
- <NButton class="dropdown-button" style="margin: 0 8px 8px 0" @click.stop="handleClickBtn">
18
- <NIcon v-if="state.spinning" :component="Reload" style="line-height: 10px" />
19
- {{ btnText }}
20
- <NIcon :component="ChevronDown" />
21
- </NButton>
22
- </slot>
23
- </NDropdown>
19
+ <n-button class="dropdown-button" style="margin: 0 8px 8px 0" @click.stop="handleClickBtn">
20
+ <!-- <n-spin v-show="state.spinning" size="small"></n-spin> -->
21
+ {{ btnText }}
22
+ <n-icon :component="ChevronDown" />
23
+ </n-button>
24
+ </slot>
25
+ </n-dropdown>
24
26
 
25
- <IdentityVerification
26
- v-model="state.identityVerification.visible"
27
- v-bind="$attrs"
28
- @success="verifiySuccess"
29
- ></IdentityVerification>
30
- </span>
27
+ <IdentityVerification
28
+ v-model="state.identityVerification.visible"
29
+ v-bind="$attrs"
30
+ @success="verifiySuccess"
31
+ ></IdentityVerification>
31
32
  </template>
32
33
 
33
- <script lang="ts">
34
+ <script lang="tsx">
34
35
  import create from '@/core/create.js';
35
36
  export default create({
36
37
  name: "ButtonPrint"
37
38
  })
38
39
  </script>
39
40
 
40
- <script setup lang="ts">
41
+ <script setup lang="tsx">
41
42
  import { ref, reactive, computed, watch, onMounted, nextTick } from 'vue'
42
- import { NDropdown, NButton, NIcon } from 'naive-ui'
43
+ import { NDropdown, NButton, NIcon, NSpin } from 'naive-ui'
43
44
  import { ChevronDown, Reload } from "@vicons/ionicons5";
44
45
  import { useMessage } from 'naive-ui'
45
46
  import type { DropdownOption } from 'naive-ui'
@@ -51,7 +52,6 @@ import moment from 'moment';
51
52
  (window as any).$message = useMessage()
52
53
  let printInstance: any = null;
53
54
 
54
- // 在.vue文件中使用导入的interface会报错,提示要使用字面量类型,当前在github上vue的issue已经有这个问题了,目前还没解决
55
55
  interface Props {
56
56
  btnText?: string
57
57
  printText?: string
@@ -65,6 +65,8 @@ interface Props {
65
65
  queryTemplateParams?: Function
66
66
  strategy?: string
67
67
  printParams?: any[]
68
+ clickPrevFn?: Function,
69
+ noDataMsg?: string
68
70
  }
69
71
  const props = withDefaults(defineProps<Props>(), {
70
72
  params: () => ([]),
@@ -78,8 +80,10 @@ const props = withDefaults(defineProps<Props>(), {
78
80
  queryPrintFormatByNumber: () => Promise.resolve({}),
79
81
  queryTemplateParams: () => Promise.resolve({}),
80
82
  strategy: 'MULTI',
83
+ clickPrevFn: () => Promise.resolve(true),
84
+ noDataMsg: '请选中需要打印的数据'
81
85
  });
82
- const emit = defineEmits(['success', 'error']);
86
+ const emit = defineEmits(['success', 'error', 'clickoutside']);
83
87
 
84
88
  const state = reactive({
85
89
  spinning: false,
@@ -117,6 +121,9 @@ const currentFormatItem = computed(() => {
117
121
  })
118
122
  const formatTitle = computed(() => (currentFormatItem.value as any).name || '格式选择')
119
123
 
124
+ const renderLabel = (option: DropdownOption) => {
125
+ return <span class={{'active': option.key === state.currentFormatId}}>{option.label}</span>
126
+ }
120
127
  const getTemplateIdByFormatId = (id: string | number) => {
121
128
  let find: any = state.formatList.find((item: any) => item.id === id);
122
129
  return find.templateId;
@@ -266,21 +273,13 @@ const handleSelect = (key: string) => {
266
273
  break;
267
274
  default:
268
275
  state.currentFormatId = key;
276
+ state.visible = false
269
277
  break;
270
278
  }
271
279
  }
272
280
  const handleClickOutside = () => {
273
281
  state.visible = false;
274
- }
275
- const handleClickWrap = () => {
276
- setTimeout(() => {
277
- state.visible = true;
278
- }, 0);
279
- }
280
- const setTimeoutSpin = () => {
281
- (state as any).spinTimer = setTimeout(() => {
282
- state.spinning = true;
283
- }, 1500);
282
+ emit('clickoutside')
284
283
  }
285
284
  const instantiatePrintSDK = () => {
286
285
  if (printInstance) return false;
@@ -314,15 +313,9 @@ const formatFormatList = (list: any[]): any => {
314
313
 
315
314
  return formatList;
316
315
  }
317
- const setLoaded = () => {
318
- state.spinning = false;
319
- if (!state.spinTimer) return false;
320
- clearTimeout(state.spinTimer);
321
- state.spinTimer = null;
322
- }
323
316
  const requestError = () => {
324
317
  state.isInited = false;
325
- setLoaded();
318
+ state.spinning = false;
326
319
  setTimeout(() => {
327
320
  state.visible = false;
328
321
  }, 0);
@@ -376,6 +369,7 @@ const initCRM = async (formatListResult: any) => {
376
369
  state.formatList = formatListResult ? formatFormatList(formatListResult.obj) : [];
377
370
  console.log('formatListResult', formatListResult)
378
371
  state.currentFormatId = getDefaultFormatId(state.formatList, 'defaultFlag');
372
+ setOptions()
379
373
 
380
374
  if (!state.currentFormatId) {
381
375
  (window as any).$message.error('获取打印格式失败,请联系管理员!');
@@ -392,24 +386,29 @@ const initCRM = async (formatListResult: any) => {
392
386
  } else {
393
387
  return requestError();
394
388
  }
395
-
396
389
  state.printParams = formatParams(state.templateParams, props.params);
397
390
  }
398
391
  const init = async () => {
399
392
  if (state.isInited) return true;
400
393
  state.isInited = true;
401
394
 
402
- setTimeoutSpin();
395
+ state.spinning = true;
403
396
 
404
397
  instantiatePrintSDK();
405
398
  const formatListResult = await props.queryPrintFormatByNumber()
406
399
  await initCRM(formatListResult);
407
400
 
408
- setLoaded();
401
+ state.spinning = false;
409
402
 
410
403
  return true;
411
404
  }
412
405
  const handleClickBtn = async () => {
406
+ const status = await props.clickPrevFn()
407
+ if (!status) return
408
+ if (!props.params?.length) {
409
+ (window as any).$message.warning(props.noDataMsg)
410
+ return
411
+ }
413
412
  if (!state.visible) {
414
413
  let result = await init();
415
414
  if (!result) return false;
@@ -473,3 +472,10 @@ watch(() => props.params,
473
472
  margin-bottom: 8px;
474
473
  }
475
474
  </style>
475
+ <style lang="less">
476
+ .rowFoldHideBtnList-dropdown {
477
+ .n-dropdown-menu-wrapper span.active {
478
+ color: #5585f5;
479
+ }
480
+ }
481
+ </style>
@@ -6,11 +6,11 @@
6
6
  :show="modelValue"
7
7
  :close-on-esc="false"
8
8
  :show-icon="false"
9
- :style="{ width: style.width, maxHeight: style.height, overflowY: 'auto' }"
10
- @after-leave="handleClickClose"
9
+ :style="{ width: style.width, overflowY: 'auto' }"
10
+ @close="handleClickClose"
11
11
  >
12
12
  <div class="content">
13
- <NForm class="login-form" ref="formRef" :model="form" :rules="rules">
13
+ <NForm class="login-form-button-print" ref="formRef" :model="form" :rules="rules">
14
14
  <NFormItem path="account">
15
15
  <NInput v-model:value="form.account" placeholder="请输入账号" />
16
16
  </NFormItem>
@@ -61,7 +61,7 @@ const rules: FormRules = {
61
61
  }
62
62
  const style = {
63
63
  width: '416px',
64
- height: '328px'
64
+ // height: '328px'
65
65
  }
66
66
  const formRef = ref<FormInst | null>(null)
67
67
 
@@ -99,22 +99,23 @@ watch(() => props.modelValue,
99
99
 
100
100
  </script>
101
101
  <style lang="less" scoped>
102
- .login-form {
103
- padding-top: 15px;
104
- &:deep(.n-input) {
105
- height: 50px;
106
- font-size: 14px;
107
- color: #757575;
108
- border-radius: 6px;
109
- }
110
- }
111
102
  .login-form-button {
112
103
  width: 100%;
113
104
  height: 50px;
114
- background: #2d7aff;
115
105
  border-radius: 24px;
116
- border-color: #2d7aff !important;
117
106
  font-size: 16px;
118
107
  color: #ffffff;
119
108
  }
120
109
  </style>
110
+ <style lang="less">
111
+ .login-form-button-print {
112
+ padding-top: 15px;
113
+ .n-input {
114
+ height: 50px;
115
+ line-height: 50px;
116
+ font-size: 14px;
117
+ color: #757575;
118
+ border-radius: 6px;
119
+ }
120
+ }
121
+ </style>