Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
refactor: 优化部分 ref API 使用方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Mar 11, 2024
1 parent e9d3865 commit e6fa9f6
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 80 deletions.
3 changes: 2 additions & 1 deletion src/views/login/components/email-login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const { t } = useI18n();
const router = useRouter();
const userStore = useUserStore();
const formRef = ref();
const loading = ref(false);
const captchaLoading = ref(false);
const captchaDisable = ref(false);
Expand Down Expand Up @@ -47,7 +48,7 @@
*/
const handleSendCaptcha = () => {
if (captchaLoading.value) return;
proxy.$refs.formRef.validateField('email', (valid: any) => {
formRef.value.validateField('email', (valid: any) => {
if (!valid) {
captchaLoading.value = true;
captchaBtnNameKey.value = 'login.captcha.ing';
Expand Down
5 changes: 3 additions & 2 deletions src/views/login/components/phone-login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const { t } = useI18n();
const router = useRouter();
const userStore = useUserStore();
const formRef = ref();
const loading = ref(false);
const captchaLoading = ref(false);
const captchaDisable = ref(true);
Expand Down Expand Up @@ -43,7 +44,7 @@
*/
const handleOpenBehaviorCaptcha = () => {
if (captchaLoading.value) return;
proxy.$refs.formRef.validateField('phone', (valid: any) => {
formRef.value.validateField('phone', (valid: any) => {
if (!valid) {
proxy.$refs.verifyRef.show();
}
Expand All @@ -65,7 +66,7 @@
*/
const handleSendCaptcha = (captchaParam: BehaviorCaptchaReq) => {
if (captchaLoading.value) return;
proxy.$refs.formRef.validateField('phone', (valid: any) => {
formRef.value.validateField('phone', (valid: any) => {
if (!valid) {
captchaLoading.value = true;
captchaBtnNameKey.value = 'login.captcha.ing';
Expand Down
5 changes: 3 additions & 2 deletions src/views/monitor/log/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'success_failure_status_enum',
);
const queryFormRef = ref();
const loginLogList = ref<LoginLogRecord[]>([]);
const total = ref(0);
const loading = ref(false);
Expand Down Expand Up @@ -55,7 +56,7 @@
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
Expand Down Expand Up @@ -94,7 +95,7 @@
<div class="header">
<!-- 搜索栏 -->
<div class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="status" hide-label>
<a-select
v-model="queryParams.status"
Expand Down
5 changes: 3 additions & 2 deletions src/views/monitor/log/operation/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'success_failure_status_enum'
);
const queryFormRef = ref();
const operationLogList = ref<OperationLogRecord[]>([]);
const total = ref(0);
const loading = ref(false);
Expand Down Expand Up @@ -56,7 +57,7 @@
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
Expand Down Expand Up @@ -95,7 +96,7 @@
<div class="header">
<!-- 搜索栏 -->
<div class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="description" hide-label>
<a-input
v-model="queryParams.description"
Expand Down
5 changes: 3 additions & 2 deletions src/views/monitor/log/system/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
const { proxy } = getCurrentInstance() as any;
const { copy, copied } = useClipboard();
const queryFormRef = ref();
const systemLogList = ref<SystemLogRecord[]>([]);
const systemLog = ref<SystemLogDetailRecord>({
traceId: '',
Expand Down Expand Up @@ -112,7 +113,7 @@
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
Expand Down Expand Up @@ -151,7 +152,7 @@
<div class="header">
<!-- 搜索栏 -->
<div class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="createTime" hide-label>
<date-range-picker v-model="queryParams.createTime" />
</a-form-item>
Expand Down
7 changes: 4 additions & 3 deletions src/views/monitor/online/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import checkPermission from '@/utils/permission';
const { proxy } = getCurrentInstance() as any;
const queryFormRef = ref();
const tableRef = ref();
const dataList = ref<DataRecord[]>([]);
const total = ref(0);
const loading = ref(false);
Expand Down Expand Up @@ -63,7 +64,7 @@
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
Expand Down Expand Up @@ -102,7 +103,7 @@
<div class="header">
<!-- 搜索栏 -->
<div class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="nickname" hide-label>
<a-input
v-model="queryParams.nickname"
Expand Down
15 changes: 9 additions & 6 deletions src/views/system/announcement/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
'announcement_status_enum',
);
const queryFormRef = ref();
const formRef = ref();
const tableRef = ref();
const dataList = ref<DataRecord[]>([]);
const dataDetail = ref<DataRecord>({});
const total = ref(0);
Expand Down Expand Up @@ -97,22 +100,22 @@
*/
const reset = () => {
form.value = {};
proxy.$refs.formRef?.resetFields();
formRef.value?.resetFields();
};
/**
* 取消
*/
const handleCancel = () => {
visible.value = false;
proxy.$refs.formRef.resetFields();
formRef.value.resetFields();
};
/**
* 确定
*/
const handleOk = () => {
proxy.$refs.formRef.validate((valid: any) => {
formRef.value.validate((valid: any) => {
if (!valid) {
if (form.value.id !== undefined) {
update(form.value, form.value.id).then((res) => {
Expand Down Expand Up @@ -185,7 +188,7 @@
del(ids).then((res) => {
proxy.$message.success(res.msg);
getList();
proxy.$refs.tableRef.selectAll(false);
tableRef.value.selectAll(false);
});
};
Expand Down Expand Up @@ -228,7 +231,7 @@
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
Expand Down Expand Up @@ -267,7 +270,7 @@
<div class="header">
<!-- 搜索栏 -->
<div v-if="showQuery" class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="title" hide-label>
<a-input
v-model="queryParams.title"
Expand Down
3 changes: 2 additions & 1 deletion src/views/system/config/components/basic-setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { useAppStore } from '@/store';
const { proxy } = getCurrentInstance() as any;
const formRef = ref();
const dataList = ref<DataRecord[]>([]);
const isEdit = ref(false);
const logoFile = ref<FileItem>({ uid: '-1' });
Expand Down Expand Up @@ -81,7 +82,7 @@
* 保存
*/
const handleSave = () => {
proxy.$refs.formRef.validate((valid: any) => {
formRef.value.validate((valid: any) => {
if (!valid) {
const optionList: DataRecord[] = Object.entries(form.value).map(
(item) => {
Expand Down
21 changes: 12 additions & 9 deletions src/views/system/dept/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
const { proxy } = getCurrentInstance() as any;
const { dis_enable_status_enum } = proxy.useDict('dis_enable_status_enum');
const queryFormRef = ref();
const formRef = ref();
const tableRef = ref();
const dataList = ref<DataRecord[]>([]);
const dataDetail = ref<DataRecord>({});
const ids = ref<Array<number>>([]);
Expand Down Expand Up @@ -64,7 +67,7 @@
.then((res) => {
dataList.value = res.data;
setTimeout(() => {
proxy.$refs.tableRef.expandAll();
tableRef.value.expandAll();
}, 0);
})
.finally(() => {
Expand Down Expand Up @@ -110,22 +113,22 @@
form.value = {
sort: 999,
};
proxy.$refs.formRef?.resetFields();
formRef.value?.resetFields();
};
/**
* 取消
*/
const handleCancel = () => {
visible.value = false;
proxy.$refs.formRef.resetFields();
formRef.value.resetFields();
};
/**
* 确定
*/
const handleOk = () => {
proxy.$refs.formRef.validate((valid: any) => {
formRef.value.validate((valid: any) => {
if (!valid) {
if (form.value.id !== undefined) {
update(form.value, form.value.id).then((res) => {
Expand Down Expand Up @@ -197,7 +200,7 @@
del(ids).then((res) => {
proxy.$message.success(res.msg);
getList();
proxy.$refs.tableRef.selectAll(false);
tableRef.value.selectAll(false);
});
};
Expand All @@ -208,7 +211,7 @@
if (rowKeys.find((key: any) => key === rowKey)) {
if (record.children) {
record.children.forEach((r) => {
proxy.$refs.tableRef.select(r.id);
tableRef.value.select(r.id);
rowKeys.push(r.id);
if (r.children) {
handleSelect(rowKeys, rowKey, r);
Expand All @@ -221,7 +224,7 @@
rowKeys.findIndex((key: number | undefined) => key === r.id),
1,
);
proxy.$refs.tableRef.select(r.id, false);
tableRef.value.select(r.id, false);
if (r.children) {
handleSelect(rowKeys, rowKey, r);
}
Expand Down Expand Up @@ -297,7 +300,7 @@
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
</script>
Expand All @@ -316,7 +319,7 @@
<div class="header">
<!-- 搜索栏 -->
<div v-if="showQuery" class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="name" hide-label>
<a-input
v-model="queryParams.name"
Expand Down
17 changes: 10 additions & 7 deletions src/views/system/dict/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
const { proxy } = getCurrentInstance() as any;
const queryFormRef = ref();
const formRef = ref();
const tableRef = ref();
const dataList = ref<DataRecord[]>([]);
const total = ref(0);
const ids = ref<Array<number>>([]);
Expand Down Expand Up @@ -129,22 +132,22 @@
*/
const reset = () => {
form.value = {};
proxy.$refs.formRef?.resetFields();
formRef.value?.resetFields();
};
/**
* 取消
*/
const handleCancel = () => {
visible.value = false;
proxy.$refs.formRef.resetFields();
formRef.value.resetFields();
};
/**
* 确定
*/
const handleOk = () => {
proxy.$refs.formRef.validate((valid: any) => {
formRef.value.validate((valid: any) => {
if (!valid) {
if (form.value.id !== undefined) {
update(form.value, form.value.id).then((res) => {
Expand Down Expand Up @@ -191,7 +194,7 @@
del(ids).then((res) => {
proxy.$message.success(res.msg);
getList();
proxy.$refs.tableRef.selectAll(false);
tableRef.value.selectAll(false);
});
};
Expand Down Expand Up @@ -223,15 +226,15 @@
* 查询
*/
const handleQuery = () => {
proxy.$refs.tableRef.selectAll(false);
tableRef.value.selectAll(false);
getList();
};
/**
* 重置
*/
const resetQuery = () => {
proxy.$refs.queryRef.resetFields();
queryFormRef.value.resetFields();
handleQuery();
};
Expand Down Expand Up @@ -272,7 +275,7 @@
<div class="header">
<!-- 搜索栏 -->
<div v-if="showQuery" class="header-query">
<a-form ref="queryRef" :model="queryParams" layout="inline">
<a-form ref="queryFormRef" :model="queryParams" layout="inline">
<a-form-item field="name" hide-label>
<a-input
v-model="queryParams.name"
Expand Down
Loading

0 comments on commit e6fa9f6

Please sign in to comment.