@xizs/nuxt-antui 0.0.9 → 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.
@@ -14,8 +14,8 @@ type TableFormItemType = {
14
14
  export type TablePropsType = {
15
15
  form?: TableFormItemType[],
16
16
  formOptions: {
17
- search: boolean,
18
- reset: boolean,
17
+ search?: boolean,
18
+ reset?: boolean,
19
19
  export: boolean,
20
20
  },
21
21
  table: {
@@ -50,15 +50,16 @@ let dateRange = defineComponent({
50
50
  item:{
51
51
  type:Object as ()=>TableFormItemType,
52
52
  required:true
53
- }
53
+ },
54
+
54
55
  },
55
56
  setup(props) {
56
57
  let {t:$t} = useI18n()
57
58
 
58
59
  let value = watchRef(ref([]),(nv,ov)=>{
59
60
  if(nv?.length>0){
60
- props.form[props.item.key[0] as string] = nv[0].format('YYYY-MM-DD 00:00:00')
61
- props.form[props.item.key[1] as string] = nv[1].format('YYYY-MM-DD 23:59:59')
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')
62
63
  }else{
63
64
  props.form[props.item.key[0] as string] = ''
64
65
  props.form[props.item.key[1] as string] = ''
@@ -66,8 +67,9 @@ let dateRange = defineComponent({
66
67
  })
67
68
  watch([() => props.form[props.item.key[0] as string],()=>props.form[props.item.key[1] as string]], (nv) => {
68
69
  console.log(nv)
69
- value.value[0]=nv[0]
70
- value.value[1]=nv[1]
70
+ if (nv[0] == '') {
71
+ value.value = []
72
+ }
71
73
  })
72
74
  const rangePresets = ref([
73
75
  { label: $t('今天'), value: [dayjs(), dayjs()] },
@@ -88,7 +90,7 @@ const FormItems:Record<string, (form: any, item: TableFormItemType) => any> = {
88
90
  },
89
91
  select: (form: any, item: TableFormItemType) => {
90
92
  let {t:$t} = useI18n()
91
- 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>
92
94
  },
93
95
  selectTenant: (form: any, item: TableFormItemType) => {
94
96
  let { t: $t } = useI18n()
@@ -144,7 +146,11 @@ export const FormTableProps = {
144
146
  type:Object as () => any,
145
147
  required:true
146
148
  },
147
- }
149
+ isInitLoad: {
150
+ type: Boolean,
151
+ default: true
152
+ }
153
+ }
148
154
 
149
155
  export default defineComponent({
150
156
  name: 'TableLayout',
@@ -180,7 +186,13 @@ export default defineComponent({
180
186
  })
181
187
 
182
188
 
183
- 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
+ }
184
196
  let res:any = await props.table.data({...form.value,...pagination})
185
197
  if(Array.isArray(res)){
186
198
  res = {
@@ -194,6 +206,7 @@ export default defineComponent({
194
206
  }
195
207
  }
196
208
  }
209
+ console.log(res)
197
210
  pagination.total = res.meta.pagination.total
198
211
  pagination.pageSize = res.meta.pagination.per_page
199
212
  pagination.page = res.meta.pagination.current_page
@@ -231,33 +244,36 @@ export default defineComponent({
231
244
  </div>
232
245
  </AForm>}
233
246
  {slots.center?.()}
234
- <div class="flex-1 overflow-scroll flex flex-col">
235
- {slots.content?.(tableData.value) ??
236
- <ATable
237
- row-selection={props.table.enableSelection?rowSelection:null}
238
- rowKey={props.table.rowKey??((row)=>row.id)}
239
- loading={tableData.loading}
240
- // scroll={{x: true}}
241
- columns={props.table.columns}
242
- pagination={false}
243
- // sticky={tableData.value.length>0}
244
- v-slots={{
245
- headerCell: ({ title,column }: any) => (
246
- <div style={{'white-space': 'nowrap'}}>
247
- {title}
248
- </div>
249
- ),
250
- bodyCell:(row:any)=>{
251
- if(row.column?.customRender!=null){
252
- return row.column.customRender(row)
253
- }
254
- return <div class="whitespace-nowrap" style={{ width:row.column.width??'100px'}}>{row.text}</div>
255
- },
256
- ...props.table['v-slots']
257
- }}
258
- dataSource={tableData.value}
259
- />
260
- }
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>
261
277
  </div>
262
278
 
263
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.9",
4
+ "version": "0.0.10",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",