br-dionysus 0.9.12 → 0.9.13

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,4 +1,11 @@
1
1
  import type { Ref } from 'vue';
2
+ /** 页码配置 */
3
+ export interface PageConfig {
4
+ /** 分页大小 */
5
+ pageSize: number;
6
+ /** 分页大小可选项 */
7
+ pageSizesOptions: number[];
8
+ }
2
9
  /** 表格列配置(单个) */
3
10
  export interface TableConfigItem {
4
11
  /** 最小列宽 */
@@ -31,5 +38,11 @@ declare const useTableConfig: (name: string, tableTitle: TableTitle[], tableData
31
38
  headerDragend: (newWidth: number, oldWidth: number, column: any) => void;
32
39
  initColumnFilter: (tableData: any[]) => void;
33
40
  filtersValue: Ref<FilterValue>;
41
+ page: Ref<{
42
+ total: number;
43
+ pageSize: number;
44
+ currentPage: number;
45
+ pageSizesOptions: number[];
46
+ }>;
34
47
  };
35
48
  export default useTableConfig;
@@ -44,6 +44,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
44
44
  clear: () => void;
45
45
  focus: () => void;
46
46
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
47
+ "update:modelValue": (...args: any[]) => void;
47
48
  selected: (...args: any[]) => void;
48
49
  toPage: (...args: any[]) => void;
49
50
  selectMultiple: (...args: any[]) => void;
@@ -89,6 +90,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
89
90
  scrollbarAlwaysOn: boolean;
90
91
  allowCreate: boolean;
91
92
  }>>> & {
93
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
92
94
  onSelected?: ((...args: any[]) => any) | undefined;
93
95
  onSelectMultiple?: ((...args: any[]) => any) | undefined;
94
96
  onToPage?: ((...args: any[]) => any) | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "br-dionysus",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
4
4
  "scripts": {
5
5
  "dev": "vite --config ./build/base.config.ts",
6
6
  "build:doc": "vue-tsc --noEmit && vite build --config ./build/doc.config.ts && node script/copyDir.js",
@@ -1,5 +1,13 @@
1
1
  import { ref, watch, computed } from 'vue'
2
2
  import type { Ref } from 'vue'
3
+ import { Page } from '../../typings/class'
4
+ /** 页码配置 */
5
+ export interface PageConfig {
6
+ /** 分页大小 */
7
+ pageSize: number
8
+ /** 分页大小可选项 */
9
+ pageSizesOptions: number[]
10
+ }
3
11
 
4
12
  /** 表格列配置(单个) */
5
13
  export interface TableConfigItem {
@@ -12,7 +20,7 @@ export interface TableConfigItem {
12
20
  /** 列名 */
13
21
  label: string,
14
22
  /** 表头对齐方式, 若不设置该项,则使用表格的对齐方式 */
15
- headerAlign: 'left' | 'center' | 'right'
23
+ headerAlign: 'left' | 'center' | 'right',
16
24
  }
17
25
 
18
26
  /** 表格配置 */
@@ -27,7 +35,6 @@ interface Column {
27
35
  export interface FilterValue {
28
36
  [key: string]: Array<string | number>
29
37
  }
30
-
31
38
  /**
32
39
  * 表格配置
33
40
  * @param {string} name 表格唯一标识
@@ -38,7 +45,8 @@ const useTableConfig = (name: string, tableTitle: TableTitle[], tableData: Ref <
38
45
  /** 表格列头 */
39
46
  const _tableTitle: Ref<TableTitle[]> = ref<TableTitle[]>([])
40
47
  const tableConfig: Ref<TableConfig> = ref<TableConfig>(JSON.parse(localStorage.getItem('tableConfig' + name) || '{}'))
41
-
48
+ const pageConfig = JSON.parse(localStorage.getItem('tablePage' + name) || '{"pageSize":50,"pageSizesOptions":[50,100,300,500,800]}')
49
+ const page = ref<Page>(new Page(pageConfig))
42
50
  /** 列筛选 */
43
51
  const filterMethod = (value: string, row: any, column: Column) => {
44
52
  return row[column.property] === value
@@ -59,7 +67,6 @@ const useTableConfig = (name: string, tableTitle: TableTitle[], tableData: Ref <
59
67
  }
60
68
  tableConfig.value[item.prop].label = item.label
61
69
  })
62
-
63
70
  const syncTableTitle = () => {
64
71
  _tableTitle.value = tableTitle.map(item => {
65
72
  return {
@@ -88,6 +95,14 @@ const useTableConfig = (name: string, tableTitle: TableTitle[], tableData: Ref <
88
95
  { deep: true }
89
96
  )
90
97
 
98
+ watch(
99
+ () => page.value,
100
+ (item) => {
101
+ localStorage.setItem('tablePage' + name, JSON.stringify({ pageSize: item.pageSize, pageSizesOptions: item.pageSizesOptions }))
102
+ },
103
+ { deep: true }
104
+ )
105
+
91
106
  /** 初始化列筛选 */
92
107
  const initColumnFilter = (tableData: any[]) => {
93
108
  _tableTitle.value = _tableTitle.value.map(item => {
@@ -120,7 +135,8 @@ const useTableConfig = (name: string, tableTitle: TableTitle[], tableData: Ref <
120
135
  tableConfig,
121
136
  headerDragend,
122
137
  initColumnFilter,
123
- filtersValue
138
+ filtersValue,
139
+ page
124
140
  }
125
141
  }
126
142
  export default useTableConfig
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <div>
3
3
  <p>1</p>
4
+ <p>0{{ code }}0</p>
4
5
  <m-new-select-table
5
6
  class="zzz"
6
7
  ref="selectRef"
@@ -19,17 +20,18 @@
19
20
  allowCreate
20
21
  filterable
21
22
  remote
23
+ multiple
22
24
  :remoteMethod="remoteMethod"
23
25
  ></m-new-select-table>
24
26
  <p>2</p>
25
27
  <m-new-select-table
26
28
  class="zzz"
27
29
  ref="selectRef"
28
- v-model="code"
30
+ v-model="code2"
29
31
  placeholder="请选择单号"
30
32
  :tableTitle="commodityOptionsTitle"
31
33
  :options="options"
32
- :keywords="{label: 'ApprovedQtyPU',value: 'DocNo' }"
34
+ :keywords="{ label: 'ApprovedQtyPU',value: 'DocNo' }"
33
35
  size="small"
34
36
  @selected="selected"
35
37
  @selectMultiple="selectMultiple"
@@ -44,7 +46,7 @@
44
46
  ></m-new-select-table>
45
47
  <p>1</p>
46
48
  <el-select
47
- v-model="code"
49
+ v-model="code3"
48
50
  filterable
49
51
  remote
50
52
  :remoteMethod="remoteMethod"
@@ -87,7 +89,9 @@ const commodityOptionsTitle: TableTitle[] = [{
87
89
  }]
88
90
  const selectRef: any = ref<HTMLElement | null>(null)
89
91
 
90
- const code = ref<string | number | Array<string | number>>('')
92
+ const code = ref<string | number | Array<string | number>>([])
93
+ const code2 = ref<string | number | Array<string | number>>('')
94
+ const code3 = ref<string | number | Array<string | number>>('')
91
95
 
92
96
  const total = ref(0)
93
97
  const options = ref<any[]>([])
@@ -108,7 +112,7 @@ const getDataList = (page: Page = new Page(), str: string = '') => {
108
112
  }
109
113
 
110
114
  const selected = (value: string | number | Array<number | string>) => {
111
- console.log(value)
115
+ // console.log(value)
112
116
  // code.value = value
113
117
  // console.log('selected',value)
114
118
  // // console.log('selected', row)
@@ -1,5 +1,7 @@
1
1
  <template>
2
2
  <div class="g-box g-select-table-box">
3
+ <p>{{ allowCreateRow }}</p>
4
+ <p>{{ props.allowCreate }}</p>
3
5
  <el-select
4
6
  ref="selectRef"
5
7
  v-bind="selectAttr"
@@ -12,7 +14,7 @@
12
14
  :value-key="props.keywords.value"
13
15
  :remote-method="remoteMethodHandle"
14
16
  :filter-method="props.remote ? null : filterMethodHandle"
15
- :model-value="props.multiple ? state.defaultValue : selectDefaultLabel"
17
+ v-model="modelValue"
16
18
  @removeTag="removeTag"
17
19
  @clear="clear"
18
20
  :filterable="props.filterable"
@@ -98,6 +100,7 @@ import {
98
100
  watch,
99
101
  reactive
100
102
  } from 'vue'
103
+ import { ElSelect, ElTable } from 'element-plus'
101
104
  import { Page } from './../../typings/class'
102
105
 
103
106
  const props = withDefaults(defineProps<{
@@ -128,8 +131,7 @@ const props = withDefaults(defineProps<{
128
131
  filterMethod: null,
129
132
  filterable: false,
130
133
  remote: false,
131
- remoteMethod: () => {
132
- },
134
+ remoteMethod: () => {},
133
135
  options: () => [],
134
136
  tableTitle: () => [],
135
137
  multiple: false,
@@ -141,29 +143,27 @@ const props = withDefaults(defineProps<{
141
143
  allowCreate: false
142
144
  })
143
145
 
144
- const selectDefaultLabel: any = ref(props.modelValue) // 单选赋值
146
+ const modelValue = ref<string | number | Array<number | string>>(props.modelValue)
145
147
 
146
148
  // 获取ref
147
- const selectRef: any = ref<HTMLElement | null>(null)
148
- const selectTableRef: any = ref<HTMLElement | null>(null)
149
+ const selectRef = ref<InstanceType<typeof ElSelect> | null>(null)
150
+ const selectTableRef = ref<InstanceType<typeof ElTable> | null>(null)
149
151
 
150
152
  // 组件内使用自定义
151
153
  const isVisible = ref(false) // 是否显示隐藏下拉框
152
154
  const state = reactive<{
153
155
  tabData: Option[],
154
156
  ids: string | number | Array<string | number>,
155
- defaultValue: string | number | Array<string | number>,
156
157
  selectRowS: any[],
157
- addList: any[]
158
+ searchValue: string // 搜索值
158
159
  }>({
159
160
  tabData: props.options,
160
161
  ids: [], // 多选id集合
161
- defaultValue: props.modelValue,
162
162
  selectRowS: [],
163
- addList: []
163
+ searchValue: ''
164
164
  })
165
165
  // 抛出事件
166
- const emit = defineEmits(['selected', 'selectMultiple', 'toPage'])
166
+ const emit = defineEmits(['selected', 'selectMultiple', 'toPage', 'update:modelValue'])
167
167
 
168
168
  watch(() => props.options, (val) => {
169
169
  state.tabData = val
@@ -179,10 +179,23 @@ watch(() => props.modelValue, (val) => {
179
179
  watch(() => props.total, () => {
180
180
  page.total = props.total as number
181
181
  })
182
+ watch(() => modelValue.value, (val, oval) => {
183
+ emit('update:modelValue', modelValue.value)
184
+ })
182
185
 
186
+ const allowCreateRow = computed(() => {
187
+ const modelValue = props.multiple ? props.modelValue as Array<string | number> : [props.modelValue as string | number]
188
+ const value = [...modelValue, state.searchValue].filter(item => item)
189
+ return value
190
+ .filter(item => !props.options.some(node => node[props.keywords.value] === item))
191
+ .map(item => ({
192
+ [props.keywords.label]: item,
193
+ [props.keywords.value]: item
194
+ }))
195
+ })
183
196
  const tabDataMap = computed(() => {
184
197
  if (!props.allowCreate) return state.tabData
185
- return state.tabData.concat(state.addList)
198
+ return [...state.tabData, ...allowCreateRow.value]
186
199
  })
187
200
 
188
201
  // 点击行事件
@@ -190,8 +203,7 @@ const rowClick = (row: Option) => {
190
203
  if (props.multiple) return selectTableRef.value.setCurrentRow() // 是多选不要
191
204
  const val = tabDataMap.value.find(item => row[props.keywords.value] === item[props.keywords.value])
192
205
  if (!val) return false
193
- state.defaultValue = val[props.keywords.label]
194
- selectDefaultLabel.value = state.defaultValue
206
+ modelValue.value = val[props.keywords.label]
195
207
  blur()
196
208
 
197
209
  emit('selected', val[props.keywords.value], val)
@@ -205,11 +217,11 @@ const selectMultiple = () => {
205
217
 
206
218
  // 多选事件
207
219
  const selectionChange = (Selection: Option[]) => {
208
- state.defaultValue = Selection.map((item) => item[props.keywords.label])
209
- state.ids = Selection.map((item) => item[props.keywords.value])
210
- state.selectRowS = Selection
211
- if (props.isAffirmBtn) return // 有确认按钮不走多选事件
212
- emit('selected', state.ids, state.selectRowS)
220
+ // modelValue.value = Selection.map((item) => item[props.keywords.label])
221
+ // state.ids = Selection.map((item) => item[props.keywords.value])
222
+ // state.selectRowS = Selection
223
+ // if (props.isAffirmBtn) return // 有确认按钮不走多选事件
224
+ // emit('selected', state.ids, state.selectRowS)
213
225
  }
214
226
  // tags删除后回调
215
227
  const removeTag = (tag: any) => {
@@ -224,7 +236,6 @@ const defaultBackFillValue = () => {
224
236
  const modelArray = props.modelValue as Array<string | number>
225
237
  const newArr = (state.tabData as Option[]).filter(item => modelArray.includes(item[props.keywords.value as keyof typeof item]))
226
238
  setTimeout(() => {
227
- state.defaultValue = newArr.map((item) => item[props.keywords.label])
228
239
  newArr.forEach((row) => {
229
240
  const arr = state.tabData.filter(
230
241
  (item) => item[props.keywords.value] === row[props.keywords.value]
@@ -234,38 +245,30 @@ const defaultBackFillValue = () => {
234
245
  })
235
246
  })
236
247
  } else {
237
- const item = state.tabData.find(item => props.modelValue === item[props.keywords.value])
238
- if (!item) return false
239
- state.defaultValue = item[props.keywords.label]
240
- selectDefaultLabel.value = state.defaultValue
248
+ // const item = state.tabData.find(item => props.modelValue === item[props.keywords.value])
249
+ // if (!item) return false
250
+ // modelValue.value = item[props.keywords.label]
241
251
  }
242
252
  }
243
253
  // // 搜索过滤
244
254
  const filterMethodHandle = (val: string) => {
255
+ state.searchValue = val
245
256
  if (props.filterable && props.filterMethod) return props.filterMethod(val, page)
246
257
  const tableData = JSON.parse(JSON.stringify(props.options))
247
258
  if (!tableData.length) return null
248
259
  state.tabData = tableData.filter((item: Option) => item[props.keywords.label].toString().includes(val))
249
- allowCreate(val)
250
- }
251
- const allowCreate = (val: string) => {
252
- if (!props.allowCreate) return
253
- if (!val) return
254
- const row = {
255
- [props.keywords.label]: val,
256
- [props.keywords.value]: val
257
- }
258
- state.tabData.push(row as Option)
259
260
  }
260
261
 
261
262
  const remoteMethodHandle = (query: string) => {
263
+ state.searchValue = query
262
264
  if (!props.remote) return false
263
265
 
264
- selectRef.value.expanded = true
265
- const el = lastOf(selectRef.value.contentId)
266
- if (el instanceof HTMLElement) {
267
- el.style.display = 'block'
268
- }
266
+ // selectRef.value.expanded = true
267
+ // const el = lastOf(selectRef.value.contentId)
268
+ selectRef?.value?.tooltipRef?.onOpen()
269
+ // if (el instanceof HTMLElement) {
270
+ // el.style.display = 'block'
271
+ // }
269
272
  return props.remoteMethod(query, page)
270
273
  }
271
274
  // 表格显示隐藏回调
@@ -276,12 +279,11 @@ const visibleChange = (visible: boolean) => {
276
279
  const clear = () => {
277
280
  if (props.multiple) {
278
281
  selectTableRef.value.clearSelection()
279
- state.defaultValue = []
282
+ modelValue.value = []
280
283
  } else {
281
284
  // 取消高亮
282
285
  selectTableRef.value.setCurrentRow()
283
- selectDefaultLabel.value = null
284
- state.defaultValue = ''
286
+ modelValue.value = ''
285
287
  }
286
288
  }
287
289
 
@@ -338,22 +340,23 @@ const focus = () => {
338
340
 
339
341
  selectRef.value.focus()
340
342
  selectRef.value.expanded = true
341
- const inputEl = lastOfTow(selectRef.value.contentId)
342
- if (!inputEl) return
343
- inputEl.addEventListener('keydown', (e: any) => {
344
- if (e.key !== 'Enter' || !props.allowCreate) return false
345
- const row = tabDataMap.value.find(item => item[props.keywords.label] === e.target.value)
346
- if (!row) return
347
- if (props.multiple) {
348
- selectTableRef.value.toggleRowSelection(row, true)
349
- } else {
350
- rowClick(row)
351
- }
352
- })
343
+ // const inputEl = lastOfTow(selectRef.value.contentId)
344
+ // if (!inputEl) return
345
+ // inputEl.addEventListener('keydown', (e: any) => {
346
+ // if (e.key !== 'Enter' || !props.allowCreate) return false
347
+ // const row = tabDataMap.value.find(item => item[props.keywords.label] === e.target.value)
348
+ // if (!row) return
349
+ // if (props.multiple) {
350
+ // selectTableRef.value.toggleRowSelection(row, true)
351
+ // } else {
352
+ // rowClick(row)
353
+ // }
354
+ // })
353
355
  }
354
356
  const changeBlur = () => {
355
- const el = lastOf(selectRef.value.contentId)
356
- if (el instanceof HTMLElement) el.style.display = 'none'
357
+ // const el = lastOf(selectRef.value.contentId)
358
+ selectRef?.value?.tooltipRef?.onClose()
359
+ // if (el instanceof HTMLElement) el.style.display = 'none'
357
360
  }
358
361
  // 触发select隐藏
359
362
  const blur = () => {
@@ -1,11 +0,0 @@
1
- <template>
2
-
3
- </template>
4
-
5
- <script setup lang="ts">
6
-
7
- </script>
8
-
9
- <style scoped lang="scss">
10
-
11
- </style>