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 >
5959import { Message } from ' @arco-design/web-vue'
6060import { useWindowSize } from ' @vueuse/core'
6161import AiEditor from ' ./components/index.vue'
62- import { useTabsStore } from ' @/stores'
62+ import { addNotice , getNotice , updateNotice } from ' @/apis/system/notice'
63+ import { listUserDict } from ' @/apis'
6364import { 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'
6567import { useForm } from ' @/hooks'
6668import { useDict } from ' @/hooks/app'
67- import { listUserDict } from ' @/apis'
68- import type { LabelValueState } from ' @/types/global'
6969
7070const { width } = useWindowSize ()
71- const { notice_type } = useDict (' notice_type' )
72- const containerRef = ref <HTMLElement | null >()
73- const tabsStore = useTabsStore ()
7471const route = useRoute ()
75- const formRef = ref <InstanceType <typeof GiForm >>()
72+ const router = useRouter ()
73+ const tabsStore = useTabsStore ()
74+
7675const { 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+
7788const { 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
9197const columns: Columns = reactive ([
9298 {
@@ -149,17 +155,18 @@ const onUpdate = async (id: string) => {
149155
150156// 返回
151157const 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
195202const userList = ref <LabelValueState []>([])
196203onMounted (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