Skip to content

Commit 901213d

Browse files
committed
refactor: 优化部分代码
1 parent f702e03 commit 901213d

File tree

16 files changed

+110
-97
lines changed

16 files changed

+110
-97
lines changed

src/views/code/generator/GenConfigDrawer.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ const options: Options = {
146146
grid: { cols: 2 },
147147
btns: { hide: true },
148148
}
149+
const { form, resetForm } = useForm({
150+
isOverride: false,
151+
})
149152
const formColumns: Columns = reactive([
150153
{
151154
label: '作者名称',
@@ -198,8 +201,8 @@ const formColumns: Columns = reactive([
198201
type: 'switch',
199202
props: {
200203
type: 'round',
201-
checkedValue: 1,
202-
uncheckedValue: 2,
204+
checkedValue: true,
205+
uncheckedValue: false,
203206
checkedText: '',
204207
uncheckedText: '',
205208
},
@@ -233,10 +236,6 @@ const columns: TableInstanceColumns[] = [
233236
{ title: '关联字典', slotName: 'dictCode' },
234237
]
235238
236-
const { form, resetForm } = useForm({
237-
isOverride: false,
238-
})
239-
240239
// 重置
241240
const reset = () => {
242241
formRef.value?.formRef?.resetFields()
@@ -281,6 +280,7 @@ const onOpen = async (tableName: string, comment: string) => {
281280
// 查询生成配置
282281
const { data } = await getGenConfig(tableName)
283282
Object.assign(form, data)
283+
form.isOverride = form.isOverride || false
284284
visible.value = true
285285
// 查询字段配置
286286
await getDataList(tableName, false)

src/views/login/components/account/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const handleLogin = async () => {
113113
})
114114
tabsStore.reset()
115115
const { redirect, ...othersQuery } = router.currentRoute.value.query
116-
router.push({
116+
await router.push({
117117
path: (redirect as string) || '/',
118118
query: {
119119
...othersQuery,

src/views/open/app/AppAddModal.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const options: Options = {
3737
btns: { hide: true },
3838
}
3939
40+
const { form, resetForm } = useForm({
41+
status: 1,
42+
})
43+
4044
const columns: Columns = reactive([
4145
{
4246
label: '名称',
@@ -46,7 +50,7 @@ const columns: Columns = reactive([
4650
},
4751
{
4852
label: '失效时间',
49-
field: 'expirationTime',
53+
field: 'expireTime',
5054
type: 'date-picker',
5155
props: {
5256
placeholder: '请选择失效时间',
@@ -76,10 +80,6 @@ const columns: Columns = reactive([
7680
},
7781
])
7882
79-
const { form, resetForm } = useForm({
80-
status: 1,
81-
})
82-
8383
// 重置
8484
const reset = () => {
8585
formRef.value?.formRef?.resetFields()

src/views/schedule/job/JobAddModal.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:title="title"
55
:mask-closable="false"
66
:esc-to-close="false"
7-
:width="width >= 600 ? 600 : '100%'"
7+
:width="width >= 700 ? 700 : '100%'"
88
@before-ok="save"
99
@close="reset"
1010
>
@@ -182,6 +182,7 @@ import { addJob, listGroup, updateJob } from '@/apis/schedule/job'
182182
import { useForm } from '@/hooks'
183183
import { useDict } from '@/hooks/app'
184184
import CronGeneratorModal from '@/components/GenCron/CronModel/index.vue'
185+
import type { LabelValueState } from '@/types/global'
185186
186187
const emit = defineEmits<{
187188
(e: 'save-success'): void
@@ -196,7 +197,7 @@ const visible = ref(false)
196197
const isUpdate = computed(() => !!dataId.value)
197198
const title = computed(() => (isUpdate.value ? '修改任务' : '新增任务'))
198199
const formRef = ref<FormInstance>()
199-
const groupList = ref()
200+
const groupList = ref<LabelValueState[]>([])
200201
const genModal = ref()
201202
const { job_trigger_type_enum, job_task_type_enum, job_route_strategy_enum, job_block_strategy_enum } = useDict(
202203
'job_trigger_type_enum',

src/views/setting/profile/BasicInfoUpdateModal.vue

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,27 @@
1717
import { useWindowSize } from '@vueuse/core'
1818
import { Message } from '@arco-design/web-vue'
1919
import { updateUserBaseInfo } from '@/apis/system'
20-
import { type Columns, GiForm } from '@/components/GiForm'
20+
import { type Columns, GiForm, type Options } from '@/components/GiForm'
2121
import { useForm } from '@/hooks'
2222
import { useUserStore } from '@/stores'
2323
2424
const { width } = useWindowSize()
25+
const userStore = useUserStore()
26+
27+
const userInfo = computed(() => userStore.userInfo)
28+
const visible = ref(false)
29+
const formRef = ref<InstanceType<typeof GiForm>>()
2530
2631
const options: Options = {
2732
form: { size: 'large' },
2833
btns: { hide: true },
2934
}
3035
36+
const { form, resetForm } = useForm({
37+
nickname: userInfo.value.nickname,
38+
gender: userInfo.value.gender,
39+
})
40+
3141
const columns: Columns = reactive([
3242
{
3343
label: '昵称',
@@ -48,27 +58,12 @@ const columns: Columns = reactive([
4858
},
4959
])
5060
51-
const userStore = useUserStore()
52-
const userInfo = computed(() => userStore.userInfo)
53-
const { form, resetForm } = useForm({
54-
nickname: userInfo.value.nickname,
55-
gender: userInfo.value.gender,
56-
})
57-
58-
const formRef = ref<InstanceType<typeof GiForm>>()
5961
// 重置
6062
const reset = () => {
6163
formRef.value?.formRef?.resetFields()
6264
resetForm()
6365
}
6466
65-
const visible = ref(false)
66-
// 修改
67-
const onUpdate = async () => {
68-
reset()
69-
visible.value = true
70-
}
71-
7267
// 保存
7368
const save = async () => {
7469
const isInvalid = await formRef.value?.formRef?.validate()
@@ -84,5 +79,11 @@ const save = async () => {
8479
}
8580
}
8681
82+
// 修改
83+
const onUpdate = async () => {
84+
reset()
85+
visible.value = true
86+
}
87+
8788
defineExpose({ onUpdate })
8889
</script>

src/views/system/dept/DeptAddModal.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const options: Options = {
5555
btns: { hide: true },
5656
}
5757
58+
const { form, resetForm } = useForm({
59+
sort: 999,
60+
status: 1,
61+
})
62+
5863
const columns: Columns = reactive([
5964
{
6065
label: '上级部门',
@@ -118,11 +123,6 @@ const columns: Columns = reactive([
118123
},
119124
])
120125
121-
const { form, resetForm } = useForm({
122-
sort: 999,
123-
status: 1,
124-
})
125-
126126
// 重置
127127
const reset = () => {
128128
formRef.value?.formRef?.resetFields()

src/views/system/dict/DictItemAddModal.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
<script setup lang="ts">
2525
import { Message } from '@arco-design/web-vue'
26+
import { useWindowSize } from '@vueuse/core'
2627
import { addDictItem, getDictItem, updateDictItem } from '@/apis/system/dict'
2728
import { type Columns, GiForm, type Options } from '@/components/GiForm'
2829
import { useForm } from '@/hooks'
@@ -31,6 +32,8 @@ const emit = defineEmits<{
3132
(e: 'save-success'): void
3233
}>()
3334
35+
const { width } = useWindowSize()
36+
3437
const dataId = ref('')
3538
const dictId = ref('')
3639
const visible = ref(false)
@@ -43,6 +46,12 @@ const options: Options = {
4346
btns: { hide: true },
4447
}
4548
49+
const { form, resetForm } = useForm({
50+
color: 'blue',
51+
sort: 999,
52+
status: 1,
53+
})
54+
4655
const columns: Columns = reactive([
4756
{ label: '标签', field: 'label', type: 'input', rules: [{ required: true, message: '请输入标签' }] },
4857
{ label: '', field: 'value', type: 'input', rules: [{ required: true, message: '请输入值' }] },
@@ -79,12 +88,6 @@ const columns: Columns = reactive([
7988
},
8089
])
8190
82-
const { form, resetForm } = useForm({
83-
color: 'blue',
84-
sort: 999,
85-
status: 1,
86-
})
87-
8891
// 重置
8992
const reset = () => {
9093
formRef.value?.formRef?.resetFields()

src/views/system/dict/tree/DictAddModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const options: Options = {
3737
btns: { hide: true },
3838
}
3939
40+
const { form, resetForm } = useForm({})
41+
4042
const columns: Columns = reactive([
4143
{ label: '名称', field: 'name', type: 'input', rules: [{ required: true, message: '请输入名称' }] },
4244
{ label: '编码', field: 'code', type: 'input', disabled: () => isUpdate.value, rules: [{ required: true, message: '请输入编码' }] },
@@ -51,8 +53,6 @@ const columns: Columns = reactive([
5153
},
5254
])
5355
54-
const { form, resetForm } = useForm({})
55-
5656
// 重置
5757
const reset = () => {
5858
formRef.value?.formRef?.resetFields()

src/views/system/file/main/FileAsideStatistics.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</a-space>
1212
<div v-if="chartData.length > 0">
1313
<a-divider />
14-
<VCharts :option="option" autoresize :style="{ height: '120px', width: '150px' }" />
14+
<VCharts :option="chartOption" autoresize :style="{ height: '120px', width: '150px' }" />
1515
</div>
1616
</section>
1717
</template>
@@ -38,7 +38,7 @@ const totalData = ref<FileStatisticsResp>({
3838
})
3939
const chartData = ref<Array<{ name: string, value: number, size: string }>>([])
4040
const statisticValueStyle = { 'color': '#5856D6', 'font-size': '18px' }
41-
const { option } = useChart(() => {
41+
const { chartOption } = useChart(() => {
4242
return {
4343
grid: {
4444
left: 0,

src/views/system/notice/add/index.vue

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<div ref="containerRef" class="detail">
33
<div class="detail_header">
44
<a-affix :target="(containerRef as HTMLElement)">
5-
<a-page-header title="通知公告" :subtitle="type === 'edit' ? '修改' : '新增'" @back="onBack">
5+
<a-page-header title="通知公告" :subtitle="title" @back="onBack">
66
<template #extra>
7-
<a-button type="primary" @click="onReleased">
7+
<a-button type="primary" @click="save">
88
<template #icon>
9-
<icon-save v-if="type === 'edit'" />
9+
<icon-save v-if="isUpdate" />
1010
<icon-send v-else />
1111
</template>
1212
<template #default>
13-
{{ type === 'edit' ? '保存' : '发布' }}
13+
{{ isUpdate ? '保存' : '发布' }}
1414
</template>
1515
</a-button>
1616
</template>
@@ -59,21 +59,32 @@
5959
import { Message } from '@arco-design/web-vue'
6060
import { useWindowSize } from '@vueuse/core'
6161
import AiEditor from './components/index.vue'
62-
import { useTabsStore } from '@/stores'
62+
import { addNotice, getNotice, updateNotice } from '@/apis/system/notice'
63+
import { listUserDict } from '@/apis'
6364
import { type Columns, GiForm, type Options } from '@/components/GiForm'
64-
import { addNotice, getNotice, updateNotice } from '@/apis/system'
65+
import type { LabelValueState } from '@/types/global'
66+
import { useTabsStore } from '@/stores'
6567
import { useForm } from '@/hooks'
6668
import { useDict } from '@/hooks/app'
67-
import { listUserDict } from '@/apis'
68-
import type { LabelValueState } from '@/types/global'
6969
7070
const { width } = useWindowSize()
71-
const { notice_type } = useDict('notice_type')
72-
const containerRef = ref<HTMLElement | null>()
73-
const tabsStore = useTabsStore()
7471
const route = useRoute()
75-
const formRef = ref<InstanceType<typeof GiForm>>()
72+
const router = useRouter()
73+
const tabsStore = useTabsStore()
74+
7675
const { id, type } = route.query
76+
const isUpdate = computed(() => type === 'update')
77+
const title = computed(() => (isUpdate.value ? '修改' : '新增'))
78+
const containerRef = ref<HTMLElement | null>()
79+
const formRef = ref<InstanceType<typeof GiForm>>()
80+
const { notice_type } = useDict('notice_type')
81+
82+
const options: Options = {
83+
form: { size: 'large' },
84+
grid: { cols: 2 },
85+
btns: { hide: true },
86+
}
87+
7788
const { form, resetForm } = useForm({
7889
title: '',
7990
type: '',
@@ -82,11 +93,6 @@ const { form, resetForm } = useForm({
8293
content: '',
8394
noticeScope: 1,
8495
})
85-
const options: Options = {
86-
form: { size: 'large' },
87-
grid: { cols: 2 },
88-
btns: { hide: true },
89-
}
9096
9197
const columns: Columns = reactive([
9298
{
@@ -149,17 +155,18 @@ const onUpdate = async (id: string) => {
149155
150156
// 返回
151157
const onBack = () => {
158+
router.back()
152159
tabsStore.closeCurrent(route.path)
153160
}
154161
155-
// 发布
156-
const onReleased = async () => {
162+
// 保存
163+
const save = async () => {
157164
const isInvalid = await formRef.value?.formRef?.validate()
158165
if (isInvalid) return false
159166
try {
160167
// 通知范围 所有人 去除指定用户
161168
form.noticeUsers = form.noticeScope === 1 ? null : form.noticeUsers
162-
if (type === 'edit') {
169+
if (isUpdate.value) {
163170
await updateNotice(form, id as string)
164171
Message.success('修改成功')
165172
} else {
@@ -194,9 +201,9 @@ const onSelectUser = (value: string[]) => {
194201
195202
const userList = ref<LabelValueState[]>([])
196203
onMounted(async () => {
197-
// 当id存在与type为edit时,执行修改操作
198-
if (id && type === 'edit') {
199-
onUpdate(id as string)
204+
// 当id存在与type为update时,执行修改操作
205+
if (id && isUpdate.value) {
206+
await onUpdate(id as string)
200207
}
201208
// 获取所有用户
202209
const { data } = await listUserDict()

0 commit comments

Comments
 (0)