Skip to content

Commit cf95959

Browse files
committed
Vue3 重构:Review 敏感词管理
1 parent 45058a9 commit cf95959

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/views/system/sensitiveWord/form.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<script setup lang="ts">
4949
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
5050
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
51+
import { CommonStatusEnum } from '@/utils/constants'
5152
5253
const { t } = useI18n() // 国际化
5354
const message = useMessage() // 消息弹窗
@@ -56,11 +57,10 @@ const modelVisible = ref(false) // 弹窗的是否展示
5657
const modelTitle = ref('') // 弹窗的标题
5758
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
5859
const formType = ref('') // 表单的类型:create - 新增;update - 修改
59-
const tags = ref([])
6060
const formData = ref({
6161
id: undefined,
6262
name: '',
63-
status: true,
63+
status: CommonStatusEnum.ENABLE,
6464
description: '',
6565
tags: []
6666
})
@@ -69,6 +69,7 @@ const formRules = reactive({
6969
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
7070
})
7171
const formRef = ref() // 表单 Ref
72+
const tags = ref([]) // todo @blue-syd:在 openModal 里加载下
7273
7374
/** 打开弹窗 */
7475
const openModal = async (type: string, id?: number) => {
@@ -101,10 +102,10 @@ const submitForm = async () => {
101102
try {
102103
const data = formData.value as unknown as SensitiveWordApi.SensitiveWordVO
103104
if (formType.value === 'create') {
104-
await SensitiveWordApi.createSensitiveWordApi(data)
105+
await SensitiveWordApi.createSensitiveWordApi(data) // TODO @blue-syd:去掉 API 后缀
105106
message.success(t('common.createSuccess'))
106107
} else {
107-
await SensitiveWordApi.updateSensitiveWordApi(data)
108+
await SensitiveWordApi.updateSensitiveWordApi(data) // TODO @blue-syd:去掉 API 后缀
108109
message.success(t('common.updateSuccess'))
109110
}
110111
modelVisible.value = false
@@ -120,7 +121,7 @@ const resetForm = () => {
120121
formData.value = {
121122
id: undefined,
122123
name: '',
123-
status: true,
124+
status: CommonStatusEnum.ENABLE,
124125
description: '',
125126
tags: []
126127
}

src/views/system/sensitiveWord/index.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
4141
/>
4242
</el-form-item>
43-
4443
<el-form-item>
4544
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
4645
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
@@ -82,9 +81,11 @@
8281
:key="index"
8382
v-for="(tag, index) in scope.row.tags"
8483
:index="index"
84+
class="mr-5px"
8585
>
8686
{{ tag }}
8787
</el-tag>
88+
&nbsp; &nbsp;
8889
</template>
8990
</el-table-column>
9091
<el-table-column
@@ -132,14 +133,13 @@ import { DICT_TYPE, getDictOptions } from '@/utils/dict'
132133
import { dateFormatter } from '@/utils/formatTime'
133134
import download from '@/utils/download'
134135
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
135-
import ConfigForm from './form.vue'
136+
import ConfigForm from './form.vue' // TODO @blue-syd:组件名不对
136137
const message = useMessage() // 消息弹窗
137138
const { t } = useI18n() // 国际化
138139
139140
const loading = ref(true) // 列表的加载中
140141
const total = ref(0) // 列表的总页数
141142
const list = ref([]) // 列表的数据
142-
const tags = ref([])
143143
const queryParams = reactive({
144144
pageNo: 1,
145145
pageSize: 10,
@@ -150,25 +150,20 @@ const queryParams = reactive({
150150
})
151151
const queryFormRef = ref() // 搜索的表单
152152
const exportLoading = ref(false) // 导出的加载中
153+
const tags = ref([])
153154
154155
/** 查询参数列表 */
155156
const getList = async () => {
156157
loading.value = true
157158
try {
158-
const data = await SensitiveWordApi.getSensitiveWordPageApi(queryParams)
159+
const data = await SensitiveWordApi.getSensitiveWordPageApi(queryParams) // TODO @blue-syd:去掉 API 后缀哈
159160
list.value = data.list
160161
total.value = data.total
161162
} finally {
162163
loading.value = false
163164
}
164165
}
165166
166-
/** 初始化标签select*/
167-
const getTags = async () => {
168-
const data = await SensitiveWordApi.getSensitiveWordTagsApi()
169-
tags.value = data
170-
}
171-
172167
/** 搜索按钮操作 */
173168
const handleQuery = () => {
174169
queryParams.pageNo = 1
@@ -187,6 +182,8 @@ const openModal = (type: string, id?: number) => {
187182
modalRef.value.openModal(type, id)
188183
}
189184
185+
// TODO @blue-syd:还少一个【测试】按钮的功能,参见 http://dashboard.yudao.iocoder.cn/system/sensitive-word
186+
190187
/** 删除按钮操作 */
191188
const handleDelete = async (id: number) => {
192189
try {
@@ -207,14 +204,19 @@ const handleExport = async () => {
207204
await message.exportConfirm()
208205
// 发起导出
209206
exportLoading.value = true
210-
const data = await SensitiveWordApi.exportSensitiveWordApi(queryParams)
207+
const data = await SensitiveWordApi.exportSensitiveWordApi(queryParams) // TODO @blue-syd:去掉 API 后缀哈
211208
download.excel(data, '敏感词.xls')
212209
} catch {
213210
} finally {
214211
exportLoading.value = false
215212
}
216213
}
217214
215+
/** 获得 Tag 标签列表 */
216+
const getTags = async () => {
217+
tags.value = await SensitiveWordApi.getSensitiveWordTagsApi() // TODO @blue-syd:去掉 API 后缀哈
218+
}
219+
218220
/** 初始化 **/
219221
onMounted(() => {
220222
getTags()

0 commit comments

Comments
 (0)