@xizs/nuxt-antui 0.0.8 → 0.0.10

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.
@@ -12,18 +12,23 @@ type TableFormItemType = {
12
12
  }
13
13
 
14
14
  export type TablePropsType = {
15
- form?: TableFormItemType[]
16
- table: {
15
+ form?: TableFormItemType[],
16
+ formOptions: {
17
+ search?: boolean,
18
+ reset?: boolean,
19
+ export: boolean,
20
+ },
21
+ table: {
22
+ 'v-slots'?:any
23
+ enableSelection?: boolean
24
+ columns: TableColumnType[]
25
+ rowKey: (row: any) => any
26
+ data: (params:any) => any
27
+ },
28
+ footerOptions?: {
29
+ show: boolean
30
+ },
17
31
  'v-slots'?:any
18
- enableSelection?: boolean
19
- columns: TableColumnType[]
20
- rowKey: (row: any) => any
21
- data: (params:any) => any
22
- },
23
- footerOptions?: {
24
- show: boolean
25
- },
26
- 'v-slots'?:any
27
32
  }
28
33
 
29
34
  export type AttributeType = {
@@ -45,19 +50,26 @@ let dateRange = defineComponent({
45
50
  item:{
46
51
  type:Object as ()=>TableFormItemType,
47
52
  required:true
48
- }
53
+ },
54
+
49
55
  },
50
56
  setup(props) {
51
57
  let {t:$t} = useI18n()
52
58
 
53
59
  let value = watchRef(ref([]),(nv,ov)=>{
54
- if(nv?.length>0){
55
- props.form[props.item.key[0] as string] = nv[0].format('YYYY-MM-DD 00:00:00')
56
- props.form[props.item.key[1] as string] = nv[1].format('YYYY-MM-DD 23:59:59')
57
- }else{
58
- props.form[props.item.key[0] as string] = ''
59
- props.form[props.item.key[1] as string] = ''
60
- }
60
+ if(nv?.length>0){
61
+ props.form[props.item.key[0] as string] = dayjs(nv[0]).format('YYYY-MM-DD')
62
+ props.form[props.item.key[1] as string] = dayjs(nv[1]).format('YYYY-MM-DD')
63
+ }else{
64
+ props.form[props.item.key[0] as string] = ''
65
+ props.form[props.item.key[1] as string] = ''
66
+ }
67
+ })
68
+ watch([() => props.form[props.item.key[0] as string],()=>props.form[props.item.key[1] as string]], (nv) => {
69
+ console.log(nv)
70
+ if (nv[0] == '') {
71
+ value.value = []
72
+ }
61
73
  })
62
74
  const rangePresets = ref([
63
75
  { label: $t('今天'), value: [dayjs(), dayjs()] },
@@ -78,10 +90,18 @@ const FormItems:Record<string, (form: any, item: TableFormItemType) => any> = {
78
90
  },
79
91
  select: (form: any, item: TableFormItemType) => {
80
92
  let {t:$t} = useI18n()
81
- return <ASelect allowClear class="min-w-[150px]" v-model:value={form[item.key]} options={item.bind?.options} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASelect>
93
+ return <ASelect allowClear {...item.bind} class="min-w-[150px]" v-model:value={form[item.key]} options={item.bind?.options} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASelect>
94
+ },
95
+ selectTenant: (form: any, item: TableFormItemType) => {
96
+ let { t: $t } = useI18n()
97
+ watch(Const.TenantSelectList(), (nv) => {
98
+ console.log(nv)
99
+ }, {
100
+ once: true
101
+ })
102
+ return <ASelect allowClear class="min-w-[150px]" v-model:value={form[item.key]} options={Const.TenantSelectList().value} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASelect>
82
103
  },
83
104
  dateRange:(form:any,item:TableFormItemType)=>{
84
-
85
105
  return h(dateRange,{form,item})
86
106
  }
87
107
  }
@@ -93,12 +113,7 @@ export const FormTableProps = {
93
113
  required: false
94
114
  },
95
115
  formOptions:{
96
- type:Object as () => {
97
- search:boolean,
98
- reset:boolean,
99
- export:boolean,
100
- opther?:()=>any
101
- },
116
+ type:Object as ()=> TablePropsType['formOptions'],
102
117
  default:()=>({
103
118
  search:true,
104
119
  reset:true,
@@ -131,7 +146,11 @@ export const FormTableProps = {
131
146
  type:Object as () => any,
132
147
  required:true
133
148
  },
134
- }
149
+ isInitLoad: {
150
+ type: Boolean,
151
+ default: true
152
+ }
153
+ }
135
154
 
136
155
  export default defineComponent({
137
156
  name: 'TableLayout',
@@ -143,7 +162,14 @@ export default defineComponent({
143
162
  const form = ref<any>({})
144
163
  props.form?.forEach((item) => {
145
164
 
146
- form.value[item.key] = item.value
165
+ if (Array.isArray(item.key)) {
166
+ item.key.forEach((key,index) => {
167
+ form.value[key] = item.value?.[index]??''
168
+ })
169
+
170
+ } else {
171
+ form.value[item.key] = item.value??''
172
+ }
147
173
  })
148
174
  props.attribute.form = form.value
149
175
  const metaForm = JSON.parse(JSON.stringify(form.value))
@@ -160,7 +186,13 @@ export default defineComponent({
160
186
  })
161
187
 
162
188
 
163
- const tableData = asyncReactive<any[]>(async ()=>{
189
+ let _isInitLoad = props.isInitLoad
190
+ const tableData = asyncReactive<any[]>(async () => {
191
+ //初始化不加载数据
192
+ if (!_isInitLoad) {
193
+ _isInitLoad = true
194
+ return []
195
+ }
164
196
  let res:any = await props.table.data({...form.value,...pagination})
165
197
  if(Array.isArray(res)){
166
198
  res = {
@@ -174,6 +206,7 @@ export default defineComponent({
174
206
  }
175
207
  }
176
208
  }
209
+ console.log(res)
177
210
  pagination.total = res.meta.pagination.total
178
211
  pagination.pageSize = res.meta.pagination.per_page
179
212
  pagination.page = res.meta.pagination.current_page
@@ -195,6 +228,7 @@ export default defineComponent({
195
228
 
196
229
  return () => (
197
230
  <div class="flex flex-col gap-2 h-full ">
231
+ {/* {JSON.stringify(form.value)} */}
198
232
  {props.form&&<AForm layout="inline gap-2">
199
233
  {props.form?.map((item: TableFormItemType) => {
200
234
  return (
@@ -205,38 +239,41 @@ export default defineComponent({
205
239
  })}
206
240
  <div class="flex gap-2">
207
241
  {props.formOptions.search && <AButton type="primary" onClick={()=>tableData.load()}>{$t('搜索')}</AButton>}
208
- {props.formOptions.reset && <AButton onClick={() => patch(metaForm,form.value)}>{$t('重置')}</AButton>}
242
+ {props.formOptions.reset && <AButton onClick={() => patch(metaForm,form.value,true)}>{$t('重置')}</AButton>}
209
243
  {props.formOptions.export && <AButton type="primary">{$t('导出')}</AButton>}
210
244
  </div>
211
245
  </AForm>}
212
246
  {slots.center?.()}
213
- <div class="flex-1 overflow-scroll flex flex-col">
214
- {slots.content?.(tableData.value) ??
215
- <ATable
216
- row-selection={props.table.enableSelection?rowSelection:null}
217
- rowKey={props.table.rowKey??((row)=>row.id)}
218
- loading={tableData.loading}
219
- // scroll={{x: true}}
220
- columns={props.table.columns}
221
- pagination={false}
222
- // sticky={tableData.value.length>0}
223
- v-slots={{
224
- headerCell: ({ title,column }: any) => (
225
- <div style={{'white-space': 'nowrap'}}>
226
- {title}
227
- </div>
228
- ),
229
- bodyCell:(row:any)=>{
230
- if(row.column?.customRender!=null){
231
- return row.column.customRender(row)
232
- }
233
- return <div class="whitespace-nowrap" style={{ width:row.column.width??'100px'}}>{row.text}</div>
234
- },
235
- ...props.table['v-slots']
236
- }}
237
- dataSource={tableData.value}
238
- />
239
- }
247
+ <div class="flex-1 relative overflow-scroll flex flex-col">
248
+ <div class="absolute inset-0 ">
249
+ {slots.content?.(tableData.value) ??
250
+ <ATable
251
+ row-selection={props.table.enableSelection ? rowSelection : null}
252
+ rowKey={props.table.rowKey ?? ((row) => row.id)}
253
+ loading={tableData.loading}
254
+ scroll={{ x: true,}}
255
+ columns={props.table.columns}
256
+ pagination={false}
257
+ sticky={tableData.value.length>0}
258
+
259
+ v-slots={{
260
+ headerCell: ({ title, column }: any) => (
261
+ <div style={{ 'white-space': 'nowrap' }}>
262
+ {title}
263
+ </div>
264
+ ),
265
+ bodyCell: (row: any) => {
266
+ if (row.column?.customRender != null) {
267
+ return row.column.customRender(row)
268
+ }
269
+ return <div class="whitespace-nowrap" style={{ width: row.column.width ?? '100px' }}>{row.text}</div>
270
+ },
271
+ ...props.table['v-slots']
272
+ }}
273
+ dataSource={tableData.value}
274
+ />
275
+ }
276
+ </div>
240
277
  </div>
241
278
 
242
279
  {props.footerOptions.show && <div class="mt-3 flex items-center justify-between">
@@ -0,0 +1,303 @@
1
+ import { defineComponent, h, ref } from 'vue'
2
+ import { AForm, AFormItem, AInput, AButton, ATable, ASelect, APagination, ARangePicker, RedoOutlined } from '#components'
3
+ import type { TableColumnType } from 'ant-design-vue'
4
+ import dayjs from 'dayjs'
5
+
6
+ type TableFormItemType = {
7
+ label: string,
8
+ key: string,
9
+ is: string,
10
+ bind?: any,
11
+ value?:any
12
+ }
13
+
14
+ export type TableParamsType = {
15
+ form?: {
16
+ labels: TableFormItemType[],
17
+ option: {
18
+ search?: boolean,
19
+ reset?: boolean,
20
+ export?: boolean,
21
+ },
22
+ },
23
+ table: {
24
+ 'v-slots'?:any
25
+ enableSelection?: boolean
26
+ columns: TableColumnType[]
27
+ rowKey: (row: any) => any
28
+ },
29
+ data: (params: any) => any
30
+ footerOptions?: {
31
+ show: boolean
32
+ },
33
+ 'v-slots'?: {
34
+ content:(data:any)=>any
35
+ }
36
+ }
37
+
38
+ export type AttributeType = {
39
+ selectItems:any[],
40
+ selectKeys:any[],
41
+ page:number,
42
+ pageSize: number,
43
+ tableData: any[],
44
+ metaTableData:any[],
45
+ form:any
46
+ }
47
+
48
+ let dateRange = defineComponent({
49
+ props:{
50
+ form:{
51
+ type:Object as ()=>any,
52
+ required:true
53
+ },
54
+ item:{
55
+ type:Object as ()=>TableFormItemType,
56
+ required:true
57
+ },
58
+
59
+ },
60
+ setup(props) {
61
+ let {t:$t} = useI18n()
62
+
63
+ let value = watchRef(ref([]),(nv,ov)=>{
64
+ if(nv?.length>0){
65
+ props.form[props.item.key[0] as string] = dayjs(nv[0]).format('YYYY-MM-DD')
66
+ props.form[props.item.key[1] as string] = dayjs(nv[1]).format('YYYY-MM-DD')
67
+ }else{
68
+ props.form[props.item.key[0] as string] = ''
69
+ props.form[props.item.key[1] as string] = ''
70
+ }
71
+ })
72
+ watch([() => props.form[props.item.key[0] as string],()=>props.form[props.item.key[1] as string]], (nv) => {
73
+ console.log(nv)
74
+ if (nv[0] == '') {
75
+ value.value = []
76
+ }
77
+ })
78
+ const rangePresets = ref([
79
+ { label: $t('今天'), value: [dayjs(), dayjs()] },
80
+ { label: $t('昨天'), value: [dayjs().add(-1, 'd'), dayjs().add(-1, 'd')] },
81
+ { label: $t('最近7天'), value: [dayjs().add(-7, 'd'), dayjs()] },
82
+ { label: $t('最近30天'), value: [dayjs().add(-30, 'd'), dayjs()] },
83
+ ]);
84
+
85
+ return ()=><ARangePicker presets={rangePresets.value} v-model:value={value.value} />
86
+ }
87
+ })
88
+
89
+
90
+ const FormItems:Record<string, (form: any, item: TableFormItemType) => any> = {
91
+ input: (form: any, item: TableFormItemType) => {
92
+ let {t:$t} = useI18n()
93
+ return <AInput size="middle" v-model:value={form[item.key]} placeholder={$t(`请输入{label}`,{label:$t(item.label)})}></AInput>
94
+ },
95
+ select: (form: any, item: TableFormItemType) => {
96
+ let {t:$t} = useI18n()
97
+ return <ASelect allowClear {...item.bind} class="min-w-[150px]" v-model:value={form[item.key]} options={item.bind?.options} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASelect>
98
+ },
99
+ selectTenant: (form: any, item: TableFormItemType) => {
100
+ let { t: $t } = useI18n()
101
+ watch(Const.TenantSelectList(), (nv) => {
102
+ console.log(nv)
103
+ }, {
104
+ once: true
105
+ })
106
+ return <ASelect allowClear class="min-w-[150px]" v-model:value={form[item.key]} options={Const.TenantSelectList().value} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASelect>
107
+ },
108
+ dateRange:(form:any,item:TableFormItemType)=>{
109
+ return h(dateRange,{form,item})
110
+ }
111
+ }
112
+
113
+
114
+ export const FormTableProps = {
115
+ form: {
116
+ type: Object as () => TableParamsType['form'],
117
+ required: false
118
+ },
119
+
120
+ table: {
121
+ type: Object as () => TableParamsType['table'],
122
+ default: () => ({
123
+ enableSelection: false,
124
+ columns: [],
125
+ rowKey:(row:any)=>{}
126
+ })
127
+ },
128
+ data: {
129
+ type: Object as () => TableParamsType['data']
130
+ },
131
+
132
+ footerOptions: {
133
+ type: Object as () => {
134
+ show: boolean,
135
+ },
136
+ default: () => ({
137
+ show: true,
138
+ })
139
+ },
140
+ attribute:{
141
+ type: Object as () => AttributeType,
142
+ default:()=>{}
143
+ },
144
+ control:{
145
+ type:Object as () => any,
146
+ required:true
147
+ },
148
+ isInitLoad: {
149
+ type: Boolean,
150
+ default: true
151
+ }
152
+ }
153
+
154
+ export default defineComponent({
155
+ name: 'TableLayout',
156
+ props: FormTableProps,
157
+ setup(props,{slots}) {
158
+ const {t:$t} = useI18n()
159
+
160
+ //form 初始化
161
+ const form = ref<any>({})
162
+ props.form?.labels.forEach((item) => {
163
+
164
+ if (Array.isArray(item.key)) {
165
+ item.key.forEach((key,index) => {
166
+ form.value[key] = item.value?.[index]??''
167
+ })
168
+
169
+ } else {
170
+ form.value[item.key] = item.value??''
171
+ }
172
+ })
173
+ props.attribute.form = form.value
174
+ const metaForm = JSON.parse(JSON.stringify(form.value))
175
+
176
+ //table初始化
177
+ props.table.columns?.forEach((item) => {
178
+ item.title = $t(item.title as string)
179
+ })
180
+
181
+ let pagination =reactive({
182
+ page:1,
183
+ pageSize:20,
184
+ total:0
185
+ })
186
+
187
+
188
+ let _isInitLoad = props.isInitLoad
189
+ const tableData = asyncReactive<any[]>(async () => {
190
+ //初始化不加载数据
191
+ if (!_isInitLoad) {
192
+ _isInitLoad = true
193
+ return []
194
+ }
195
+ let res: any = await props.data?.({ ...form.value, ...pagination })
196
+ if(Array.isArray(res)){
197
+ res = {
198
+ list:res,
199
+ meta:{
200
+ pagination:{
201
+ total:0,
202
+ per_page:pagination.pageSize,
203
+ current_page:pagination.page
204
+ }
205
+ }
206
+ }
207
+ }
208
+ console.log(res)
209
+ pagination.total = res.meta.pagination.total
210
+ pagination.pageSize = res.meta.pagination.per_page
211
+ pagination.page = res.meta.pagination.current_page
212
+ props.attribute.metaTableData = JSON.parse(JSON.stringify(res.list))
213
+ props.attribute.tableData = res.list
214
+ return res.list
215
+ },[])
216
+
217
+
218
+ const rowSelection = {
219
+ selectedRowKeys: props.attribute?.selectKeys,
220
+ onChange: (keys:any,rows:any)=>{
221
+ props.attribute!.selectKeys.splice(0,props.attribute!.selectKeys.length,...keys)
222
+ props.attribute!.selectItems.splice(0,props.attribute!.selectItems.length,...rows)
223
+ }
224
+ }
225
+
226
+ props.control.refresh = ()=>tableData.load()
227
+
228
+ return () => (
229
+ <div class="flex flex-col gap-2 h-full ">
230
+ {/* {JSON.stringify(form.value)} */}
231
+ {props.form?.labels&&<AForm layout="inline gap-2">
232
+ {props.form?.labels?.map((item: TableFormItemType) => {
233
+ return (
234
+ <AFormItem label={$t(item.label)}>
235
+ {FormItems[item.is]?.(form.value,item)}
236
+ </AFormItem>
237
+ )
238
+ })}
239
+ <div class="flex gap-2">
240
+ {props.form?.option?.search !== false && <AButton type="primary" onClick={()=>tableData.load()}>{$t('搜索')}</AButton>}
241
+ {props.form?.option?.reset !== false && <AButton onClick={() => patch(metaForm,form.value,true)}>{$t('重置')}</AButton>}
242
+ {props.form?.option?.export !== false && <AButton type="primary">{$t('导出')}</AButton>}
243
+ </div>
244
+ </AForm>}
245
+ {slots.center?.()}
246
+ <div class="flex-1 relative overflow-scroll flex flex-col">
247
+ {slots.content?.(tableData.value) ??< div class="absolute inset-0 ">
248
+ <ATable
249
+ row-selection={props.table.enableSelection ? rowSelection : null}
250
+ rowKey={props.table.rowKey ?? ((row) => row.id)}
251
+ loading={tableData.loading}
252
+ scroll={{ x: true,}}
253
+ columns={props.table.columns}
254
+ pagination={false}
255
+ sticky={tableData.value.length>0}
256
+ v-slots={{
257
+ headerCell: ({ title, column }: any) => (
258
+ <div style={{ 'white-space': 'nowrap' }}>
259
+ {title}
260
+ </div>
261
+ ),
262
+ bodyCell: (row: any) => {
263
+ if (row.column?.customRender != null) {
264
+ return row.column.customRender(row)
265
+ }
266
+ return <div class="whitespace-nowrap" style={{ width: row.column.width ?? '100px' }}>{row.text}</div>
267
+ },
268
+ ...props.table['v-slots']
269
+ }}
270
+ dataSource={tableData.value}
271
+ />
272
+ </div>
273
+ }
274
+ </div>
275
+
276
+ {props.footerOptions.show && <div class="mt-3 flex items-center justify-between">
277
+ <div>
278
+ { props.table.enableSelection && (`${$t('选中项')}: ${props.attribute.selectKeys.length}`)}
279
+ </div>
280
+ <div class="flex items-center gap-2">
281
+ <APagination
282
+ hideOnSinglePage={true}
283
+ v-model:current={pagination.page}
284
+ total={pagination.total}
285
+ pageSize={pagination.pageSize}
286
+ onChange={(page) => {
287
+ pagination.page = page
288
+ tableData.load()
289
+ }}
290
+ pageSizeOptions={['20','50','100']}
291
+ onShowSizeChange={(current, size) => {
292
+ pagination.pageSize = size
293
+ pagination.page = 1
294
+ tableData.load()
295
+ }}
296
+ />
297
+ <AButton icon={h(RedoOutlined)} loading={tableData.loading} onClick={tableData.load} />
298
+ </div>
299
+ </div>}
300
+ </div>
301
+ )
302
+ }
303
+ })
@@ -7,8 +7,8 @@
7
7
  width="220px"
8
8
  :trigger="null"
9
9
  >
10
- <div class="text-center text-white p-2 text-lg " >
11
- LOGO
10
+ <div class="text-center text-white p-2 text-lg " >
11
+ {{props.title}}
12
12
  </div>
13
13
  <LayoutMenu :items="props.menu"></LayoutMenu>
14
14
  </a-layout-sider>
@@ -76,6 +76,7 @@ const { locales, setLocale } = useI18n()
76
76
  const collapsed = ref(false)
77
77
 
78
78
  const props = defineProps<{
79
+ title:string,
79
80
  menu: MenuItemType[]
80
81
  }>()
81
82
 
@@ -1,6 +1,7 @@
1
1
  import { ABadge, ACard, ADropdown, AMenu, ATag, EllipsisOutlined } from "#components";
2
2
  import type { TablePropsType } from "../components/global/FormTable";
3
3
  import FormTableCom from "../components/global/FormTable";
4
+ import FormTableCom2, { type TableParamsType } from "../components/global/FormTable2";
4
5
 
5
6
 
6
7
  export const FormTable = (props: TablePropsType) => {
@@ -25,6 +26,28 @@ export const FormTable = (props: TablePropsType) => {
25
26
  }
26
27
  }
27
28
 
29
+ export const FormTable2 = (props: TableParamsType) => {
30
+
31
+ const attribute = reactive({
32
+ selectItems: [],
33
+ selectKeys: [],
34
+ page: 1,
35
+ pageSize: 10,
36
+ tableData: [],
37
+ form: {}
38
+ })
39
+
40
+ const control = {
41
+ refresh: () => { }
42
+ }
43
+ console.log({ ...props, attribute, control })
44
+ return {
45
+ com: h(FormTableCom2, { ...props, attribute, control }, props['v-slots']),
46
+ attribute,
47
+ control
48
+ }
49
+ }
50
+
28
51
  export const TablePage = (props: TablePropsType) => {
29
52
  let TableParams = FormTable(props)
30
53
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xizs/nuxt-antui",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",