@xizs/nuxt-antui 0.0.10 → 0.0.11

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,11 +1,12 @@
1
1
  import { defineComponent, h, ref } from 'vue'
2
- import { AForm, AFormItem, AInput, AButton, ATable, ASelect, APagination, ARangePicker, RedoOutlined } from '#components'
2
+ import { AForm, AFormItem, AInput, AButton, ATable, ASelect, APagination, ARangePicker, RedoOutlined, ASwitch, AInputNumber } from '#components'
3
3
  import type { TableColumnType } from 'ant-design-vue'
4
4
  import dayjs from 'dayjs'
5
5
 
6
- type TableFormItemType = {
6
+
7
+ type TableFormLabelsItemType = {
7
8
  label: string,
8
- key: string,
9
+ key: string | string[],
9
10
  is: string,
10
11
  bind?: any,
11
12
  value?:any
@@ -13,14 +14,15 @@ type TableFormItemType = {
13
14
 
14
15
  export type TableParamsType = {
15
16
  form?: {
16
- labels: TableFormItemType[],
17
- option: {
17
+ labels?: TableFormLabelsItemType[],
18
+ 'v-slots'?: Record<string, ()=>any>,
19
+ option?: {
18
20
  search?: boolean,
19
21
  reset?: boolean,
20
22
  export?: boolean,
21
23
  },
22
24
  },
23
- table: {
25
+ table?: {
24
26
  'v-slots'?:any
25
27
  enableSelection?: boolean
26
28
  columns: TableColumnType[]
@@ -52,7 +54,7 @@ let dateRange = defineComponent({
52
54
  required:true
53
55
  },
54
56
  item:{
55
- type:Object as ()=>TableFormItemType,
57
+ type:Object as ()=>TableFormLabelsItemType,
56
58
  required:true
57
59
  },
58
60
 
@@ -87,25 +89,28 @@ let dateRange = defineComponent({
87
89
  })
88
90
 
89
91
 
90
- const FormItems:Record<string, (form: any, item: TableFormItemType) => any> = {
91
- input: (form: any, item: TableFormItemType) => {
92
+ const FormItems:Record<string, (form: any, item: TableFormLabelsItemType) => any> = {
93
+ input: (form: any, item: TableFormLabelsItemType) => {
92
94
  let {t:$t} = useI18n()
93
- return <AInput size="middle" v-model:value={form[item.key]} placeholder={$t(`请输入{label}`,{label:$t(item.label)})}></AInput>
95
+ return <AInput size="middle" v-model:value={form[item.key as string]} placeholder={$t(`请输入{label}`,{label:$t(item.label)})}></AInput>
94
96
  },
95
- select: (form: any, item: TableFormItemType) => {
97
+ numberRange: (form: any, item: TableFormLabelsItemType) => {
96
98
  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>
99
+ return <div class="flex items-center">
100
+ <AInputNumber class="!min-w-[150px]" v-model:value={form[item.key[0] as string]} placeholder={$t(`请输入{label}开始`,{label:$t(item.label)})}></AInputNumber>
101
+ <span class="px-1">-</span>
102
+ <AInputNumber class="!min-w-[150px]" v-model:value={form[item.key[1] as string]} placeholder={$t(`请输入{label}结束`,{label:$t(item.label)})}></AInputNumber>
103
+ </div>
98
104
  },
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>
105
+ select: (form: any, item: TableFormLabelsItemType) => {
106
+ let {t:$t} = useI18n()
107
+ return <ASelect allowClear {...item.bind} class="min-w-[150px]" v-model:value={form[item.key as string]} options={item.bind?.options} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASelect>
107
108
  },
108
- dateRange:(form:any,item:TableFormItemType)=>{
109
+ switch: (form: any, item: TableFormLabelsItemType) => {
110
+ let {t:$t} = useI18n()
111
+ return <ASwitch allowClear {...item.bind} class="min-w-[150px]" v-model:value={form[item.key as string]} options={item.bind?.options} placeholder={$t(`请选择{label}`,{label:$t(item.label)})}></ASwitch>
112
+ },
113
+ dateRange:(form:any,item:TableFormLabelsItemType)=>{
109
114
  return h(dateRange,{form,item})
110
115
  }
111
116
  }
@@ -159,7 +164,7 @@ export default defineComponent({
159
164
 
160
165
  //form 初始化
161
166
  const form = ref<any>({})
162
- props.form?.labels.forEach((item) => {
167
+ props.form?.labels?.forEach((item) => {
163
168
 
164
169
  if (Array.isArray(item.key)) {
165
170
  item.key.forEach((key,index) => {
@@ -229,7 +234,7 @@ export default defineComponent({
229
234
  <div class="flex flex-col gap-2 h-full ">
230
235
  {/* {JSON.stringify(form.value)} */}
231
236
  {props.form?.labels&&<AForm layout="inline gap-2">
232
- {props.form?.labels?.map((item: TableFormItemType) => {
237
+ {props.form?.labels?.map((item: TableFormLabelsItemType) => {
233
238
  return (
234
239
  <AFormItem label={$t(item.label)}>
235
240
  {FormItems[item.is]?.(form.value,item)}
@@ -239,8 +244,12 @@ export default defineComponent({
239
244
  <div class="flex gap-2">
240
245
  {props.form?.option?.search !== false && <AButton type="primary" onClick={()=>tableData.load()}>{$t('搜索')}</AButton>}
241
246
  {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>}
247
+ {props.form?.option?.export === true && <AButton type="primary">{$t('导出')}</AButton>}
243
248
  </div>
249
+
250
+ <div class="flex ml-auto">
251
+ {props.form['v-slots']?.extra?.()}
252
+ </div>
244
253
  </AForm>}
245
254
  {slots.center?.()}
246
255
  <div class="flex-1 relative overflow-scroll flex flex-col">
@@ -6,6 +6,7 @@
6
6
  collapsed-width="0"
7
7
  width="220px"
8
8
  :trigger="null"
9
+ class="overflow-scroll"
9
10
  >
10
11
  <div class="text-center text-white p-2 text-lg " >
11
12
  {{props.title}}
@@ -15,45 +16,50 @@
15
16
 
16
17
  <a-layout>
17
18
  <a-layout-header :style="{ background: '#fff', padding: 0 }">
18
- <div class="flex h-full items-center justify-between gap-2 px-4">
19
- <div class="flex items-center gap-2">
20
- <menu-unfold-outlined v-if="collapsed" class="trigger text-[20px]" @click="() => (collapsed = !collapsed)" />
21
- <menu-fold-outlined v-else class="trigger text-[20px]" @click="() => (collapsed = !collapsed)" />
22
- <div class="leading-4 gap-1 flex flex-col justify-center h-full">
23
- <div class="text-[12px] text-[#aaa]">{{routeInfo.names.join(' / ')}}</div>
24
- <div class="font-bold text-[18px]">{{routeInfo.name}}</div>
19
+ <div class="flex h-full items-center justify-between gap-2 px-4">
20
+ <div class="flex items-center gap-2">
21
+ <menu-unfold-outlined v-if="collapsed" class="trigger text-[20px]" @click="() => (collapsed = !collapsed)" />
22
+ <menu-fold-outlined v-else class="trigger text-[20px]" @click="() => (collapsed = !collapsed)" />
23
+ <div class="leading-4 gap-1 flex flex-col justify-center h-full">
24
+ <div class="text-[12px] text-[#aaa]">{{routeInfo?.names.join(' / ')}}</div>
25
+ <div class="font-bold text-[18px]">{{routeInfo?.name}}</div>
26
+ </div>
25
27
  </div>
26
- </div>
27
- <div class=" flex items-center">
28
- <div >
29
- <a-dropdown >
30
- <div class="h-[30px] leading-[30px] cursor-pointer">{{ useAdmin().value?.username ?? 'Admin'}}</div>
31
- <template #overlay>
32
- <a-menu>
33
- <a-menu-item @click="()=>singOut()">
34
- <a href="javascript:;">{{$t('退出')}}</a>
35
- </a-menu-item>
36
- </a-menu>
37
- </template>
38
- </a-dropdown>
39
- </div>
40
- <div class="flex items-center p-2 ml-2">
41
- <a-dropdown >
42
- <div class=" cursor-pointer">
43
- <GlobalOutlined class="text-[20px]" />
44
- </div>
45
- <template #overlay>
46
- <a-menu>
47
- <a-menu-item v-for="locale in locales" @click="setLocale(locale.code)">
48
- {{ locale.name }}
49
- </a-menu-item>
50
- </a-menu>
51
- </template>
52
- </a-dropdown>
28
+ <div class=" flex items-center">
29
+ <slot name="header-right-extend"></slot>
30
+
31
+ <div class="flex items-center p-2 ml-2">
32
+ <a-dropdown >
33
+ <div class=" cursor-pointer flex items-center">
34
+ <GlobalOutlined class="text-[26px]" />
35
+ </div>
36
+ <template #overlay>
37
+ <a-menu>
38
+ <a-menu-item v-for="locale in locales" @click="setLocale(locale.code)">
39
+ {{ locale.name }}
40
+ </a-menu-item>
41
+ </a-menu>
42
+ </template>
43
+ </a-dropdown>
44
+ </div>
45
+ <div >
46
+ <a-dropdown >
47
+ <div class="h-[30px] leading-[30px] cursor-pointer">{{ useAdmin().value?.username ?? 'Admin'}}</div>
48
+ <template #overlay>
49
+ <a-menu>
50
+ <a-menu-item v-for="item in props.adminMenu" @click="item.click">
51
+ {{ item.name }}
52
+ </a-menu-item>
53
+ <a-menu-item @click="()=>singOut()">
54
+ <a href="javascript:;">{{$t('退出')}}</a>
55
+ </a-menu-item>
56
+ </a-menu>
57
+ </template>
58
+ </a-dropdown>
59
+ </div>
53
60
  </div>
54
-
55
61
  </div>
56
- </div>
62
+
57
63
  </a-layout-header>
58
64
  <!-- <div class="p-4 bg-white" style="border-top:1px solid #eee">
59
65
  <div class="leading-4 gap-1 flex flex-col justify-center h-full">
@@ -62,7 +68,7 @@
62
68
  </div>
63
69
  </div> -->
64
70
  <a-layout-content :style="{ }" class="relative m-4">
65
- <div class="absolute top-0 left-0 right-0 bottom-0">
71
+ <div class="absolute top-0 left-0 right-0 bottom-0 overflow-scroll">
66
72
  <slot ></slot>
67
73
  </div>
68
74
  </a-layout-content>
@@ -77,10 +83,15 @@ const collapsed = ref(false)
77
83
 
78
84
  const props = defineProps<{
79
85
  title:string,
80
- menu: MenuItemType[]
86
+ menu: MenuItemType[],
87
+ adminMenu:{
88
+ name:string,
89
+ click:()=>void
90
+ }[]
81
91
  }>()
82
92
 
83
93
  let routeInfo = useRouteInfo(props.menu)
84
94
 
95
+
85
96
  </script>
86
97
 
@@ -69,8 +69,8 @@ const items = computed(()=>{
69
69
  let routeInfo = useRouteInfo(props.items)
70
70
 
71
71
  onMounted(()=>{
72
- state.selectedKeys=routeInfo.value.paths
73
- state.openKeys=routeInfo.value.paths
72
+ state.selectedKeys=routeInfo?.value?.paths
73
+ state.openKeys=routeInfo?.value?.paths
74
74
  })
75
75
 
76
76
 
@@ -0,0 +1,56 @@
1
+
2
+ export const useRouteInfo = (menuItems: any[]) =>
3
+ useState('routeName', () => {
4
+ const info = ref({
5
+ name: '',
6
+ names: [] as string[],
7
+ paths: [] as string[],
8
+ })
9
+ console.log(menuItems)
10
+
11
+ const route = useRoute()
12
+
13
+ const findPath = (
14
+ items: any[],
15
+ targetPath: string,
16
+ parents: { title: string; path: string }[] = []
17
+ ): { titles: string[]; paths: string[] } | null => {
18
+ for (const item of items) {
19
+ const current = [...parents, { title: item.title, path: item.path }]
20
+ if (item.path === targetPath) {
21
+ return {
22
+ titles: current.map((i) => i.title),
23
+ paths: current.map((i) => i.path),
24
+ }
25
+ }
26
+ if (item.children) {
27
+ const result = findPath(item.children, targetPath, current)
28
+ if (result) return result
29
+ }
30
+ }
31
+ return null
32
+ }
33
+
34
+ watch(
35
+ () => route.fullPath,
36
+ () => {
37
+ const match = findPath(menuItems, route.path)
38
+ if (match) {
39
+ info.value = {
40
+ name: match.titles.at(-1) || '',
41
+ names: match.titles,
42
+ paths: match.paths,
43
+ }
44
+ } else {
45
+ info.value = {
46
+ name: '',
47
+ names: [],
48
+ paths: [],
49
+ }
50
+ }
51
+ },
52
+ { immediate: true }
53
+ )
54
+
55
+ return info
56
+ })
@@ -58,6 +58,17 @@ export const TablePage = (props: TablePropsType) => {
58
58
  }
59
59
  }
60
60
 
61
+ export const TablePage2 = (props: TableParamsType) => {
62
+ let TableParams = FormTable2(props)
63
+
64
+ return {
65
+ ...TableParams,
66
+ com: h(ACard, { class: "absolute top-0 left-0 right-0 bottom-0 h-full", bodyStyle: { height: '100%' } }, TableParams.com)
67
+
68
+ }
69
+ }
70
+
71
+
61
72
 
62
73
  export const Table = {
63
74
  Normal: FormTable,
package/nuxt.config.ts CHANGED
@@ -21,6 +21,13 @@ export default defineNuxtConfig({
21
21
  i18n: {
22
22
  defaultLocale: 'zh',
23
23
  strategy: 'no_prefix',
24
+ compilation: {
25
+ strictMessage: false,
26
+ escapeHtml: true,
27
+ },
28
+ bundle: {
29
+ optimizeTranslationDirective: false
30
+ },
24
31
  locales: [
25
32
  { code: 'en', name: 'English', file: 'en.json' },
26
33
  { code: 'zh', name: '中文', file: 'zh.json' }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xizs/nuxt-antui",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",
package/tsconfig.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "extends": "./.playground/.nuxt/tsconfig.json",
2
+ "extends": "./.nuxt/tsconfig.json",
3
3
  }
@@ -1,15 +0,0 @@
1
- import { ACard } from "#components"
2
- import { FormTableProps } from "./FormTable"
3
-
4
- export default defineComponent({
5
-
6
- props:FormTableProps,
7
-
8
- setup(props){
9
- const {com,params} = FormTable(props)
10
-
11
- return ()=><ACard class="absolute top-0 left-0 right-0 bottom-0 h-full" bodyStyle="height:100%">
12
- <com></com>
13
- </ACard>
14
- }
15
- })