Skip to content

Commit 8a8154e

Browse files
committed
Vue3 重构:REVIEW 公众号账号
1 parent 202031d commit 8a8154e

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed

src/views/mp/account/form.vue renamed to src/views/mp/account/AccountForm.vue

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<Dialog :title="modelTitle" v-model="modelVisible">
3-
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
3+
<el-form
4+
ref="formRef"
5+
:model="formData"
6+
:rules="rules"
7+
label-width="120px"
8+
v-loading="formLoading"
9+
>
410
<el-form-item label="名称" prop="name">
511
<el-input v-model="formData.name" placeholder="请输入名称" />
612
</el-form-item>
@@ -57,24 +63,20 @@
5763
</el-form-item>
5864
</el-form>
5965
<template #footer>
60-
<div class="dialog-footer">
61-
<el-button type="primary" @click="submitForm">确 定</el-button>
62-
<el-button @click="modelVisible = false">取 消</el-button>
63-
</div>
66+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
67+
<el-button @click="modelVisible = false">取 消</el-button>
6468
</template>
6569
</Dialog>
6670
</template>
6771
<script setup lang="ts">
6872
import * as AccountApi from '@/api/mp/account'
69-
7073
const { t } = useI18n() // 国际化
7174
const message = useMessage() // 消息弹窗
7275
7376
const modelVisible = ref(false) // 弹窗的是否展示
7477
const modelTitle = ref('') // 弹窗的标题
7578
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
7679
const formType = ref('') // 表单的类型:create - 新增;update - 修改
77-
// 表单参数
7880
const formData = ref({
7981
id: undefined,
8082
name: '',
@@ -85,7 +87,6 @@ const formData = ref({
8587
aesKey: '',
8688
remark: ''
8789
})
88-
// 表单校验
8990
const rules = reactive({
9091
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
9192
account: [{ required: true, message: '公众号账号不能为空', trigger: 'blur' }],
@@ -96,7 +97,7 @@ const rules = reactive({
9697
const formRef = ref() // 表单 Ref
9798
9899
/** 打开弹窗 */
99-
const openModal = async (type: string, id?: number) => {
100+
const open = async (type: string, id?: number) => {
100101
modelVisible.value = true
101102
modelTitle.value = t('action.' + type)
102103
formType.value = type
@@ -111,12 +112,10 @@ const openModal = async (type: string, id?: number) => {
111112
}
112113
}
113114
}
114-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
115+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
115116
116117
/** 提交表单 */
117118
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
118-
119-
/** 提交按钮 */
120119
const submitForm = async () => {
121120
// 校验表单
122121
if (!formRef) return

src/views/mp/account/index.vue

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:model="queryParams"
77
ref="queryFormRef"
88
:inline="true"
9-
label-width="90px"
9+
label-width="68px"
1010
>
1111
<el-form-item label="名称" prop="name">
1212
<el-input
@@ -20,8 +20,8 @@
2020
<el-form-item>
2121
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />搜索</el-button>
2222
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" />重置</el-button>
23-
<el-button type="primary" @click="openModal('create')" v-hasPermi="['mp:account:create']"
24-
><Icon icon="ep:plus" class="mr-5px" />新增
23+
<el-button type="primary" @click="openForm('create')" v-hasPermi="['mp:account:create']">
24+
<Icon icon="ep:plus" class="mr-5px" /> 新增
2525
</el-button>
2626
</el-form-item>
2727
</el-form>
@@ -46,6 +46,14 @@
4646
alt="二维码"
4747
style="height: 100px; display: inline-block"
4848
/>
49+
<el-button
50+
link
51+
type="primary"
52+
@click="handleGenerateQrCode(scope.row)"
53+
v-hasPermi="['mp:account:qr-code']"
54+
>
55+
生成二维码
56+
</el-button>
4957
</template>
5058
</el-table-column>
5159
<el-table-column label="备注" align="center" prop="remark" />
@@ -54,30 +62,26 @@
5462
<el-button
5563
link
5664
type="primary"
57-
@click="openModal('update', scope.row.id)"
65+
@click="openForm('update', scope.row.id)"
5866
v-hasPermi="['mp:account:update']"
59-
>编辑
67+
>
68+
编辑
6069
</el-button>
6170
<el-button
6271
link
6372
type="danger"
6473
@click="handleDelete(scope.row.id)"
6574
v-hasPermi="['mp:account:delete']"
66-
>删除
67-
</el-button>
68-
<el-button
69-
link
70-
type="primary"
71-
@click="handleGenerateQrCode(scope.row)"
72-
v-hasPermi="['mp:account:qr-code']"
73-
>生成二维码
75+
>
76+
删除
7477
</el-button>
7578
<el-button
7679
link
7780
type="danger"
7881
@click="handleCleanQuota(scope.row)"
7982
v-hasPermi="['mp:account:clear-quota']"
80-
>清空 API 配额
83+
>
84+
清空 API 配额
8185
</el-button>
8286
</template>
8387
</el-table-column>
@@ -91,23 +95,20 @@
9195
@pagination="getList"
9296
/>
9397
</content-wrap>
98+
9499
<!-- 对话框(添加 / 修改) -->
95-
<account-form ref="modalRef" @success="getList" />
100+
<AccountForm ref="formRef" @success="getList" />
96101
</template>
97-
98102
<script setup lang="ts" name="MpAccount">
99103
import * as AccountApi from '@/api/mp/account'
100-
import AccountForm from './form.vue'
104+
import AccountForm from './AccountForm.vue'
101105
102106
const message = useMessage() // 消息弹窗
103107
const { t } = useI18n() // 国际化
104-
// 遮罩层
105-
const loading = ref(true)
106-
// 总条数
107-
const total = ref(0)
108-
// 公众号账号列表
109-
const list = ref([])
110-
// 查询参数
108+
109+
const loading = ref(true) // 列表的加载中
110+
const total = ref(0) // 列表的总页数
111+
const list = ref([]) // 列表的数据
111112
const queryParams = reactive({
112113
pageNo: 1,
113114
pageSize: 10,
@@ -134,16 +135,17 @@ const handleQuery = () => {
134135
queryParams.pageNo = 1
135136
getList()
136137
}
138+
137139
/** 重置按钮操作 */
138140
const resetQuery = () => {
139141
queryFormRef.value.resetFields()
140142
handleQuery()
141143
}
142144
143145
/** 添加/修改操作 */
144-
const modalRef = ref()
145-
const openModal = (type: string, id?: number) => {
146-
modalRef.value.openModal(type, id)
146+
const formRef = ref()
147+
const openForm = (type: string, id?: number) => {
148+
formRef.value.open(type, id)
147149
}
148150
149151
/** 删除按钮操作 */
@@ -158,6 +160,7 @@ const handleDelete = async (id) => {
158160
await getList()
159161
} catch {}
160162
}
163+
161164
/** 生成二维码的按钮操作 */
162165
const handleGenerateQrCode = async (row) => {
163166
try {
@@ -170,6 +173,7 @@ const handleGenerateQrCode = async (row) => {
170173
await getList()
171174
} catch {}
172175
}
176+
173177
/** 清空二维码 API 配额的按钮操作 */
174178
const handleCleanQuota = async (row) => {
175179
try {
@@ -181,6 +185,7 @@ const handleCleanQuota = async (row) => {
181185
} catch {}
182186
}
183187
188+
/** 初始化 **/
184189
onMounted(() => {
185190
getList()
186191
})

src/views/system/dept/index.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<template>
2+
<!-- 搜索工作栏 -->
23
<ContentWrap>
3-
<!-- 搜索工作栏 -->
4-
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
4+
<el-form
5+
class="-mb-15px"
6+
:model="queryParams"
7+
ref="queryFormRef"
8+
:inline="true"
9+
label-width="68px"
10+
>
511
<el-form-item label="部门名称" prop="title">
612
<el-input v-model="queryParams.name" placeholder="请输入部门名称" clearable />
713
</el-form-item>
@@ -113,7 +119,7 @@ const isExpandAll = ref(true) // 是否展开,默认全部展开
113119
const refreshTable = ref(true) // 重新渲染表格状态
114120
const loading = ref(true) // 列表的加载中
115121
116-
//获取用户列表
122+
// 获取用户列表
117123
const getUserList = async () => {
118124
const res = await getSimpleUserList()
119125
userOption.value = res
@@ -157,6 +163,7 @@ const getList = async () => {
157163
loading.value = false
158164
}
159165
}
166+
160167
/** 重置按钮操作 */
161168
const resetQuery = () => {
162169
queryParams.pageNo = 1

0 commit comments

Comments
 (0)