Commit 9e508c953fc443c9c0c08c6d16f9c58bae57a4db
1 parent
1a233184
表单提交延时loading
Showing
12 changed files
with
125 additions
and
43 deletions
src/api/request.ts
| @@ -2,7 +2,6 @@ import axios from 'axios' | @@ -2,7 +2,6 @@ import axios from 'axios' | ||
| 2 | import * as store from "@/pinia/index"; | 2 | import * as store from "@/pinia/index"; |
| 3 | import router from '@/router' | 3 | import router from '@/router' |
| 4 | import { ElMessage } from 'element-plus' | 4 | import { ElMessage } from 'element-plus' |
| 5 | -import { Stream } from 'stream'; | ||
| 6 | 5 | ||
| 7 | // 不这样写报ts类型错误,import...有一个多余的boolean类型 | 6 | // 不这样写报ts类型错误,import...有一个多余的boolean类型 |
| 8 | let url: any = import.meta.env | 7 | let url: any = import.meta.env |
| @@ -35,7 +34,7 @@ instance.interceptors.response.use( | @@ -35,7 +34,7 @@ instance.interceptors.response.use( | ||
| 35 | switch (~~response?.data?.errorCode) { | 34 | switch (~~response?.data?.errorCode) { |
| 36 | case 10002: | 35 | case 10002: |
| 37 | ElMessage.error(response?.data?.errorMessage || '登录失效'); | 36 | ElMessage.error(response?.data?.errorMessage || '登录失效'); |
| 38 | - store.family.loginStore.removeToken() | 37 | + store.family.loginStore().removeToken() |
| 39 | router.replace({ | 38 | router.replace({ |
| 40 | path: '/login' | 39 | path: '/login' |
| 41 | }) | 40 | }) |
src/layout/header.vue
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | */ | 5 | */ |
| 6 | import { getCurrentInstance, onMounted, reactive, computed } from "vue"; | 6 | import { getCurrentInstance, onMounted, reactive, computed } from "vue"; |
| 7 | import * as store from "@/pinia/index"; | 7 | import * as store from "@/pinia/index"; |
| 8 | -import { ElMessageBox } from "element-plus"; | 8 | +import { ElMessageBox, ElMessage } from "element-plus"; |
| 9 | import { Fold, Expand } from "@element-plus/icons-vue"; | 9 | import { Fold, Expand } from "@element-plus/icons-vue"; |
| 10 | import styles from "@/style/global.module.scss"; | 10 | import styles from "@/style/global.module.scss"; |
| 11 | // TIP 获取全局变量,暂时只有坏图片占位图 | 11 | // TIP 获取全局变量,暂时只有坏图片占位图 |
| @@ -31,6 +31,7 @@ const handleLogout = () => { | @@ -31,6 +31,7 @@ const handleLogout = () => { | ||
| 31 | }) | 31 | }) |
| 32 | .then(() => { | 32 | .then(() => { |
| 33 | store.family.loginStore().removeToken(); | 33 | store.family.loginStore().removeToken(); |
| 34 | + ElMessage.success('已退出登录') | ||
| 34 | }) | 35 | }) |
| 35 | .catch((error) => { | 36 | .catch((error) => { |
| 36 | console.log(error); | 37 | console.log(error); |
src/layout/menu.vue
| @@ -7,6 +7,7 @@ import { ref, computed, onMounted, reactive } from "vue"; | @@ -7,6 +7,7 @@ import { ref, computed, onMounted, reactive } from "vue"; | ||
| 7 | import * as store from "@/pinia/index"; | 7 | import * as store from "@/pinia/index"; |
| 8 | import styles from "@/style/global.module.scss"; | 8 | import styles from "@/style/global.module.scss"; |
| 9 | import MenuIcon from "./icon.vue"; | 9 | import MenuIcon from "./icon.vue"; |
| 10 | +import { useRoute } from "vue-router"; | ||
| 10 | // TIP 获取scss样式变量 | 11 | // TIP 获取scss样式变量 |
| 11 | let styleData = computed(() => { | 12 | let styleData = computed(() => { |
| 12 | return styles; | 13 | return styles; |
| @@ -26,12 +27,13 @@ onMounted(() => { | @@ -26,12 +27,13 @@ onMounted(() => { | ||
| 26 | <template> | 27 | <template> |
| 27 | <el-scrollbar wrap-class="scrollbar-wrapper"> | 28 | <el-scrollbar wrap-class="scrollbar-wrapper"> |
| 28 | <el-menu | 29 | <el-menu |
| 29 | - default-active="2" | 30 | + :default-active="useRoute().path" |
| 30 | :background-color="styleData.menuBg" | 31 | :background-color="styleData.menuBg" |
| 31 | :text-color="styleData.menuText" | 32 | :text-color="styleData.menuText" |
| 32 | :active-text-color="styleData.menuActiveText" | 33 | :active-text-color="styleData.menuActiveText" |
| 33 | class="el-menu-vertical-demo" | 34 | class="el-menu-vertical-demo" |
| 34 | :router="true" | 35 | :router="true" |
| 36 | + :unique-opened="true" | ||
| 35 | :collapse-transition="false" | 37 | :collapse-transition="false" |
| 36 | :collapse="asyncData.isCollapse" | 38 | :collapse="asyncData.isCollapse" |
| 37 | > | 39 | > |
src/pinia/modules/login.ts
| @@ -77,7 +77,6 @@ const actions = { | @@ -77,7 +77,6 @@ const actions = { | ||
| 77 | logout() | 77 | logout() |
| 78 | this.token = '' | 78 | this.token = '' |
| 79 | window.localStorage.clear() | 79 | window.localStorage.clear() |
| 80 | - ElMessage.success(msg || '已退出登录'); | ||
| 81 | setTimeout(() => { | 80 | setTimeout(() => { |
| 82 | router.replace('/login') | 81 | router.replace('/login') |
| 83 | }, 500) | 82 | }, 500) |
src/views/notify/edit.vue
| @@ -21,6 +21,7 @@ let form = reactive({ | @@ -21,6 +21,7 @@ let form = reactive({ | ||
| 21 | }, | 21 | }, |
| 22 | dataType: "", | 22 | dataType: "", |
| 23 | neighborhoods: [], | 23 | neighborhoods: [], |
| 24 | + loading: false, | ||
| 24 | }); | 25 | }); |
| 25 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); | 26 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); |
| 26 | let instance: ComponentInternalInstance | null = getCurrentInstance(); | 27 | let instance: ComponentInternalInstance | null = getCurrentInstance(); |
| @@ -57,6 +58,7 @@ const submitForm = ( | @@ -57,6 +58,7 @@ const submitForm = ( | ||
| 57 | formEl: InstanceType<typeof ElForm> | undefined, | 58 | formEl: InstanceType<typeof ElForm> | undefined, |
| 58 | type: number | 59 | type: number |
| 59 | ) => { | 60 | ) => { |
| 61 | + form.loading = true; | ||
| 60 | if (!formEl) return; | 62 | if (!formEl) return; |
| 61 | formEl.validate(async (valid) => { | 63 | formEl.validate(async (valid) => { |
| 62 | if (valid) { | 64 | if (valid) { |
| @@ -82,6 +84,7 @@ const submitForm = ( | @@ -82,6 +84,7 @@ const submitForm = ( | ||
| 82 | } | 84 | } |
| 83 | } else { | 85 | } else { |
| 84 | instance?.proxy?.$message.error("请检查表单格式"); | 86 | instance?.proxy?.$message.error("请检查表单格式"); |
| 87 | + form.loading = false; | ||
| 85 | return false; | 88 | return false; |
| 86 | } | 89 | } |
| 87 | }); | 90 | }); |
| @@ -100,6 +103,9 @@ const postApi = async (type: number) => { | @@ -100,6 +103,9 @@ const postApi = async (type: number) => { | ||
| 100 | }) | 103 | }) |
| 101 | .catch((error) => { | 104 | .catch((error) => { |
| 102 | console.log(error); | 105 | console.log(error); |
| 106 | + }) | ||
| 107 | + .finally(() => { | ||
| 108 | + form.loading = false; | ||
| 103 | }); | 109 | }); |
| 104 | }; | 110 | }; |
| 105 | /** | 111 | /** |
| @@ -189,10 +195,16 @@ onMounted(() => { | @@ -189,10 +195,16 @@ onMounted(() => { | ||
| 189 | <!-- <Tinymce></Tinymce> --> | 195 | <!-- <Tinymce></Tinymce> --> |
| 190 | </el-form-item> | 196 | </el-form-item> |
| 191 | <el-form-item style="width: 100%" v-show="form.dataType !== 'detail'"> | 197 | <el-form-item style="width: 100%" v-show="form.dataType !== 'detail'"> |
| 192 | - <el-button type="primary" @click="submitForm(ruleFormRef, 1)" | 198 | + <el-button |
| 199 | + type="primary" | ||
| 200 | + @click="submitForm(ruleFormRef, 1)" | ||
| 201 | + :loading="form.loading" | ||
| 193 | >发布</el-button | 202 | >发布</el-button |
| 194 | > | 203 | > |
| 195 | - <el-button type="primary" @click="submitForm(ruleFormRef, 0)" | 204 | + <el-button |
| 205 | + type="primary" | ||
| 206 | + @click="submitForm(ruleFormRef, 0)" | ||
| 207 | + :loading="form.loading" | ||
| 196 | >存为草稿</el-button | 208 | >存为草稿</el-button |
| 197 | > | 209 | > |
| 198 | <el-button | 210 | <el-button |
src/views/permission/edit.vue
| @@ -17,6 +17,7 @@ let form = reactive({ | @@ -17,6 +17,7 @@ let form = reactive({ | ||
| 17 | id: null, | 17 | id: null, |
| 18 | }, | 18 | }, |
| 19 | dataType: "", | 19 | dataType: "", |
| 20 | + loading: false, | ||
| 20 | }); | 21 | }); |
| 21 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); | 22 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); |
| 22 | /** | 23 | /** |
| @@ -65,6 +66,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -65,6 +66,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 65 | * 表单提交 | 66 | * 表单提交 |
| 66 | */ | 67 | */ |
| 67 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 68 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 69 | + form.loading = true; | ||
| 68 | if (!formEl) return; | 70 | if (!formEl) return; |
| 69 | formEl.validate((valid) => { | 71 | formEl.validate((valid) => { |
| 70 | if (valid) { | 72 | if (valid) { |
| @@ -77,9 +79,13 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -77,9 +79,13 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 77 | }) | 79 | }) |
| 78 | .catch((error) => { | 80 | .catch((error) => { |
| 79 | console.log(error); | 81 | console.log(error); |
| 82 | + }) | ||
| 83 | + .finally(() => { | ||
| 84 | + form.loading = false; | ||
| 80 | }); | 85 | }); |
| 81 | } else { | 86 | } else { |
| 82 | instance?.proxy?.$message.error("请检查表单格式"); | 87 | instance?.proxy?.$message.error("请检查表单格式"); |
| 88 | + form.loading = false; | ||
| 83 | return false; | 89 | return false; |
| 84 | } | 90 | } |
| 85 | }); | 91 | }); |
| @@ -173,7 +179,10 @@ onMounted(() => { | @@ -173,7 +179,10 @@ onMounted(() => { | ||
| 173 | </el-radio-group> | 179 | </el-radio-group> |
| 174 | </el-form-item> | 180 | </el-form-item> |
| 175 | <el-form-item style="width: 100%"> | 181 | <el-form-item style="width: 100%"> |
| 176 | - <el-button type="primary" @click="submitForm(ruleFormRef)" | 182 | + <el-button |
| 183 | + type="primary" | ||
| 184 | + @click="submitForm(ruleFormRef)" | ||
| 185 | + :loading="form.loading" | ||
| 177 | >提交</el-button | 186 | >提交</el-button |
| 178 | > | 187 | > |
| 179 | <el-button type="info" @click="back">返回</el-button> | 188 | <el-button type="info" @click="back">返回</el-button> |
src/views/property/edit.vue
| @@ -13,6 +13,7 @@ const { | @@ -13,6 +13,7 @@ const { | ||
| 13 | } = getCurrentInstance(); | 13 | } = getCurrentInstance(); |
| 14 | let form = reactive({ | 14 | let form = reactive({ |
| 15 | dataType: "", | 15 | dataType: "", |
| 16 | + loading: false, | ||
| 16 | data: { | 17 | data: { |
| 17 | name: "", | 18 | name: "", |
| 18 | userName: "", | 19 | userName: "", |
| @@ -114,6 +115,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -114,6 +115,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 114 | }; | 115 | }; |
| 115 | // 表单提交 | 116 | // 表单提交 |
| 116 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 117 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 118 | + form.loading = true; | ||
| 117 | if (!formEl) return; | 119 | if (!formEl) return; |
| 118 | formEl.validate((valid) => { | 120 | formEl.validate((valid) => { |
| 119 | if (valid) { | 121 | if (valid) { |
| @@ -126,9 +128,13 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -126,9 +128,13 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 126 | }) | 128 | }) |
| 127 | .catch((error) => { | 129 | .catch((error) => { |
| 128 | console.log(error); | 130 | console.log(error); |
| 131 | + }) | ||
| 132 | + .finally(() => { | ||
| 133 | + form.loading = false; | ||
| 129 | }); | 134 | }); |
| 130 | } else { | 135 | } else { |
| 131 | globalProperties.$message.error("请检查表单格式"); | 136 | globalProperties.$message.error("请检查表单格式"); |
| 137 | + form.loading = false; | ||
| 132 | return false; | 138 | return false; |
| 133 | } | 139 | } |
| 134 | }); | 140 | }); |
| @@ -243,7 +249,10 @@ onMounted(() => { | @@ -243,7 +249,10 @@ onMounted(() => { | ||
| 243 | </el-select> | 249 | </el-select> |
| 244 | </el-form-item> | 250 | </el-form-item> |
| 245 | <el-form-item style="width: 100%"> | 251 | <el-form-item style="width: 100%"> |
| 246 | - <el-button type="primary" @click="submitForm(ruleFormRef)" | 252 | + <el-button |
| 253 | + type="primary" | ||
| 254 | + @click="submitForm(ruleFormRef)" | ||
| 255 | + :loading="form.loading" | ||
| 247 | >提交</el-button | 256 | >提交</el-button |
| 248 | > | 257 | > |
| 249 | <el-button type="info" @click="resetForm(ruleFormRef)" | 258 | <el-button type="info" @click="resetForm(ruleFormRef)" |
src/views/role/edit.vue
| @@ -14,6 +14,7 @@ let form = reactive({ | @@ -14,6 +14,7 @@ let form = reactive({ | ||
| 14 | roleName: "", | 14 | roleName: "", |
| 15 | roleDesc: "", | 15 | roleDesc: "", |
| 16 | }, | 16 | }, |
| 17 | + loading: false, | ||
| 17 | dataType: "", | 18 | dataType: "", |
| 18 | }); | 19 | }); |
| 19 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); | 20 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); |
| @@ -40,6 +41,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -40,6 +41,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 40 | * 表单提交 | 41 | * 表单提交 |
| 41 | */ | 42 | */ |
| 42 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 43 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 44 | + form.loading = true; | ||
| 43 | if (!formEl) return; | 45 | if (!formEl) return; |
| 44 | formEl.validate((valid) => { | 46 | formEl.validate((valid) => { |
| 45 | if (valid) { | 47 | if (valid) { |
| @@ -52,9 +54,13 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -52,9 +54,13 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 52 | }) | 54 | }) |
| 53 | .catch((error) => { | 55 | .catch((error) => { |
| 54 | console.log(error); | 56 | console.log(error); |
| 57 | + }) | ||
| 58 | + .finally(() => { | ||
| 59 | + form.loading = false; | ||
| 55 | }); | 60 | }); |
| 56 | } else { | 61 | } else { |
| 57 | globalProperties.$message.error("请检查表单格式"); | 62 | globalProperties.$message.error("请检查表单格式"); |
| 63 | + form.loading = false; | ||
| 58 | return false; | 64 | return false; |
| 59 | } | 65 | } |
| 60 | }); | 66 | }); |
| @@ -97,7 +103,10 @@ onMounted(() => { | @@ -97,7 +103,10 @@ onMounted(() => { | ||
| 97 | /> | 103 | /> |
| 98 | </el-form-item> | 104 | </el-form-item> |
| 99 | <el-form-item style="width: 100%"> | 105 | <el-form-item style="width: 100%"> |
| 100 | - <el-button type="primary" @click="submitForm(ruleFormRef)" | 106 | + <el-button |
| 107 | + type="primary" | ||
| 108 | + @click="submitForm(ruleFormRef)" | ||
| 109 | + :loading="form.loading" | ||
| 101 | >提交</el-button | 110 | >提交</el-button |
| 102 | > | 111 | > |
| 103 | <el-button | 112 | <el-button |
| @@ -106,9 +115,7 @@ onMounted(() => { | @@ -106,9 +115,7 @@ onMounted(() => { | ||
| 106 | v-show="form.dataType === 'add'" | 115 | v-show="form.dataType === 'add'" |
| 107 | >取消</el-button | 116 | >取消</el-button |
| 108 | > | 117 | > |
| 109 | - <el-button type="info" @click="back" | ||
| 110 | - >返回</el-button | ||
| 111 | - > | 118 | + <el-button type="info" @click="back">返回</el-button> |
| 112 | </el-form-item> | 119 | </el-form-item> |
| 113 | </el-form> | 120 | </el-form> |
| 114 | </el-card> | 121 | </el-card> |
src/views/role/permission.vue
| @@ -16,6 +16,7 @@ let form = reactive({ | @@ -16,6 +16,7 @@ let form = reactive({ | ||
| 16 | roleId: useRoute().query.roleId, | 16 | roleId: useRoute().query.roleId, |
| 17 | permissionIds: [], | 17 | permissionIds: [], |
| 18 | }, | 18 | }, |
| 19 | + loading: false, | ||
| 19 | permissions: [], | 20 | permissions: [], |
| 20 | defaultPermissions: [], | 21 | defaultPermissions: [], |
| 21 | collections: [], | 22 | collections: [], |
| @@ -35,6 +36,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -35,6 +36,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 35 | * 表单提交 | 36 | * 表单提交 |
| 36 | */ | 37 | */ |
| 37 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 38 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 39 | + form.loading = true | ||
| 38 | if (!formEl) return; | 40 | if (!formEl) return; |
| 39 | formEl.validate((valid) => { | 41 | formEl.validate((valid) => { |
| 40 | if (valid) { | 42 | if (valid) { |
| @@ -47,9 +49,12 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -47,9 +49,12 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 47 | }) | 49 | }) |
| 48 | .catch((error) => { | 50 | .catch((error) => { |
| 49 | console.log(error); | 51 | console.log(error); |
| 50 | - }); | 52 | + }).finally (() => { |
| 53 | + form.loading = false | ||
| 54 | + }) | ||
| 51 | } else { | 55 | } else { |
| 52 | globalProperties.$message.error("请检查表单格式"); | 56 | globalProperties.$message.error("请检查表单格式"); |
| 57 | + form.loading = false | ||
| 53 | return false; | 58 | return false; |
| 54 | } | 59 | } |
| 55 | }); | 60 | }); |
| @@ -149,7 +154,7 @@ onMounted(() => { | @@ -149,7 +154,7 @@ onMounted(() => { | ||
| 149 | /> | 154 | /> |
| 150 | </el-form-item> | 155 | </el-form-item> |
| 151 | <el-form-item style="width: 100%"> | 156 | <el-form-item style="width: 100%"> |
| 152 | - <el-button type="primary" @click="submitForm(ruleFormRef)" | 157 | + <el-button type="primary" @click="submitForm(ruleFormRef)" :loading="form.loading" |
| 153 | >提交</el-button | 158 | >提交</el-button |
| 154 | > | 159 | > |
| 155 | <el-button type="info" @click="resetForm(ruleFormRef)" | 160 | <el-button type="info" @click="resetForm(ruleFormRef)" |
src/views/system/info.vue
| @@ -13,6 +13,7 @@ let form = reactive({ | @@ -13,6 +13,7 @@ let form = reactive({ | ||
| 13 | newPassword: "", | 13 | newPassword: "", |
| 14 | surePwd: "", | 14 | surePwd: "", |
| 15 | }, | 15 | }, |
| 16 | + loading: false, | ||
| 16 | }); | 17 | }); |
| 17 | /** | 18 | /** |
| 18 | * 验证两次输入密码一致 | 19 | * 验证两次输入密码一致 |
| @@ -65,21 +66,26 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -65,21 +66,26 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 65 | * 表单提交 | 66 | * 表单提交 |
| 66 | */ | 67 | */ |
| 67 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 68 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 69 | + form.loading = true; | ||
| 68 | if (!formEl) return; | 70 | if (!formEl) return; |
| 69 | formEl.validate((valid) => { | 71 | formEl.validate((valid) => { |
| 70 | if (valid) { | 72 | if (valid) { |
| 71 | userPwdChange(form.data) | 73 | userPwdChange(form.data) |
| 72 | .then((res) => { | 74 | .then((res) => { |
| 73 | if (res) { | 75 | if (res) { |
| 74 | - instance?.proxy?.$message.success("修改成功"); | ||
| 75 | - store.family.loginStore().removeToken("请重新登录"); | 76 | + instance?.proxy?.$message.success("修改成功,请重新登录"); |
| 77 | + store.family.loginStore().removeToken(); | ||
| 76 | } | 78 | } |
| 77 | }) | 79 | }) |
| 78 | .catch((error) => { | 80 | .catch((error) => { |
| 79 | console.log(error); | 81 | console.log(error); |
| 82 | + }) | ||
| 83 | + .finally(() => { | ||
| 84 | + form.loading = false; | ||
| 80 | }); | 85 | }); |
| 81 | } else { | 86 | } else { |
| 82 | instance?.proxy?.$message.error("请检查表单内容"); | 87 | instance?.proxy?.$message.error("请检查表单内容"); |
| 88 | + form.loading = false; | ||
| 83 | return false; | 89 | return false; |
| 84 | } | 90 | } |
| 85 | }); | 91 | }); |
| @@ -120,7 +126,10 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -120,7 +126,10 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 120 | /> | 126 | /> |
| 121 | </el-form-item> | 127 | </el-form-item> |
| 122 | <el-form-item style="width: 100%"> | 128 | <el-form-item style="width: 100%"> |
| 123 | - <el-button type="primary" @click="submitForm(ruleFormRef)" | 129 | + <el-button |
| 130 | + type="primary" | ||
| 131 | + @click="submitForm(ruleFormRef)" | ||
| 132 | + :loading="form.loading" | ||
| 124 | >提交</el-button | 133 | >提交</el-button |
| 125 | > | 134 | > |
| 126 | <el-button type="info" @click="resetForm(ruleFormRef)" | 135 | <el-button type="info" @click="resetForm(ruleFormRef)" |
src/views/user/edit.vue
| @@ -5,7 +5,7 @@ import { roleList } from "@/api/user/role"; | @@ -5,7 +5,7 @@ import { roleList } from "@/api/user/role"; | ||
| 5 | import { getTableList } from "@/api/community/residence"; | 5 | import { getTableList } from "@/api/community/residence"; |
| 6 | import { useRoute } from "vue-router"; | 6 | import { useRoute } from "vue-router"; |
| 7 | import { validMobile } from "@/utils/validate"; | 7 | import { validMobile } from "@/utils/validate"; |
| 8 | -import * as store from '@/pinia'; | 8 | +import * as store from "@/pinia"; |
| 9 | import type { ElForm } from "element-plus"; | 9 | import type { ElForm } from "element-plus"; |
| 10 | const { | 10 | const { |
| 11 | appContext: { | 11 | appContext: { |
| @@ -21,6 +21,7 @@ let form = reactive({ | @@ -21,6 +21,7 @@ let form = reactive({ | ||
| 21 | neighborhoodIds: "", | 21 | neighborhoodIds: "", |
| 22 | userId: "", | 22 | userId: "", |
| 23 | }, | 23 | }, |
| 24 | + loading: false, | ||
| 24 | dataType: "", | 25 | dataType: "", |
| 25 | roles: [], | 26 | roles: [], |
| 26 | communities: [], | 27 | communities: [], |
| @@ -29,8 +30,8 @@ let form = reactive({ | @@ -29,8 +30,8 @@ let form = reactive({ | ||
| 29 | }); | 30 | }); |
| 30 | let asyncData = reactive({ | 31 | let asyncData = reactive({ |
| 31 | userInfo: null, | 32 | userInfo: null, |
| 32 | - userType: null | ||
| 33 | -}) | 33 | + userType: null, |
| 34 | +}); | ||
| 34 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); | 35 | const ruleFormRef = ref<InstanceType<typeof ElForm>>(); |
| 35 | /** | 36 | /** |
| 36 | * 校验手机号格式 | 37 | * 校验手机号格式 |
| @@ -93,6 +94,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -93,6 +94,7 @@ const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 93 | * 表单提交 | 94 | * 表单提交 |
| 94 | */ | 95 | */ |
| 95 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 96 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 97 | + form.loading = true; | ||
| 96 | if (!formEl) return; | 98 | if (!formEl) return; |
| 97 | formEl.validate(async (valid) => { | 99 | formEl.validate(async (valid) => { |
| 98 | if (valid) { | 100 | if (valid) { |
| @@ -108,7 +110,7 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -108,7 +110,7 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 108 | roleIds: form.data.roleIds, | 110 | roleIds: form.data.roleIds, |
| 109 | userId: form.data.id, | 111 | userId: form.data.id, |
| 110 | userName: form.data.userName, | 112 | userName: form.data.userName, |
| 111 | - neighborhoodIds: form.data.neighborhoodIds | 113 | + neighborhoodIds: form.data.neighborhoodIds, |
| 112 | }); | 114 | }); |
| 113 | } | 115 | } |
| 114 | } catch (e) { | 116 | } catch (e) { |
| @@ -118,9 +120,11 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | @@ -118,9 +120,11 @@ const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | ||
| 118 | globalProperties.$message.success("操作成功"); | 120 | globalProperties.$message.success("操作成功"); |
| 119 | history.go(-1); | 121 | history.go(-1); |
| 120 | } | 122 | } |
| 123 | + form.loading = false; | ||
| 121 | } | 124 | } |
| 122 | } else { | 125 | } else { |
| 123 | globalProperties.$message.error("请检查表单格式"); | 126 | globalProperties.$message.error("请检查表单格式"); |
| 127 | + form.loading = false; | ||
| 124 | return false; | 128 | return false; |
| 125 | } | 129 | } |
| 126 | }); | 130 | }); |
| @@ -163,10 +167,10 @@ const getCommunityList = async (pageSize: number = 20) => { | @@ -163,10 +167,10 @@ const getCommunityList = async (pageSize: number = 20) => { | ||
| 163 | } | 167 | } |
| 164 | }; | 168 | }; |
| 165 | onMounted(() => { | 169 | onMounted(() => { |
| 166 | - asyncData.userInfo = store.family.loginStore().id | ||
| 167 | - asyncData.userType = store.family.loginStore().organizationType | 170 | + asyncData.userInfo = store.family.loginStore().id; |
| 171 | + asyncData.userType = store.family.loginStore().organizationType; | ||
| 168 | getRoleList(); | 172 | getRoleList(); |
| 169 | - if(~~asyncData.userType === 1) { | 173 | + if (~~asyncData.userType === 1) { |
| 170 | getCommunityList(); | 174 | getCommunityList(); |
| 171 | } | 175 | } |
| 172 | form.data = useRoute().query; | 176 | form.data = useRoute().query; |
| @@ -174,8 +178,12 @@ onMounted(() => { | @@ -174,8 +178,12 @@ onMounted(() => { | ||
| 174 | form.dataType = "add"; | 178 | form.dataType = "add"; |
| 175 | } else { | 179 | } else { |
| 176 | form.dataType = "edit"; | 180 | form.dataType = "edit"; |
| 177 | - form.checkList = form.data.roleIds? form.data.roleIds?.split(",").map((v) => v / 1): [] | ||
| 178 | - form.communityList = form.data.neighborhoodIds? form.data.neighborhoodIds.split(",").map((v) => v / 1): [] | 181 | + form.checkList = form.data.roleIds |
| 182 | + ? form.data.roleIds?.split(",").map((v) => v / 1) | ||
| 183 | + : []; | ||
| 184 | + form.communityList = form.data.neighborhoodIds | ||
| 185 | + ? form.data.neighborhoodIds.split(",").map((v) => v / 1) | ||
| 186 | + : []; | ||
| 179 | } | 187 | } |
| 180 | }); | 188 | }); |
| 181 | </script> | 189 | </script> |
| @@ -230,13 +238,20 @@ onMounted(() => { | @@ -230,13 +238,20 @@ onMounted(() => { | ||
| 230 | v-for="(item, index) in form.roles" | 238 | v-for="(item, index) in form.roles" |
| 231 | :key="index" | 239 | :key="index" |
| 232 | :label="item.id" | 240 | :label="item.id" |
| 233 | - :disabled="~~item.status === 0 || (asyncData.userInfo === 1 && item.code !== 'BUSINESS_ADMIN')" | 241 | + :disabled=" |
| 242 | + ~~item.status === 0 || | ||
| 243 | + (asyncData.userInfo === 1 && item.code !== 'BUSINESS_ADMIN') | ||
| 244 | + " | ||
| 234 | >{{ item.roleName }}</el-checkbox | 245 | >{{ item.roleName }}</el-checkbox |
| 235 | > | 246 | > |
| 236 | </el-checkbox-group> | 247 | </el-checkbox-group> |
| 237 | </el-form-item> | 248 | </el-form-item> |
| 238 | <!-- 当前登录的用户是物业管理员,表单里才有关联小区 --> | 249 | <!-- 当前登录的用户是物业管理员,表单里才有关联小区 --> |
| 239 | - <el-form-item label="小区" style="width: 100%" v-show="asyncData.userType === 1"> | 250 | + <el-form-item |
| 251 | + label="小区" | ||
| 252 | + style="width: 100%" | ||
| 253 | + v-show="asyncData.userType === 1" | ||
| 254 | + > | ||
| 240 | <el-checkbox-group | 255 | <el-checkbox-group |
| 241 | v-model="form.communityList" | 256 | v-model="form.communityList" |
| 242 | @change="(data) => (form.data.neighborhoodIds = data.join(','))" | 257 | @change="(data) => (form.data.neighborhoodIds = data.join(','))" |
| @@ -250,7 +265,10 @@ onMounted(() => { | @@ -250,7 +265,10 @@ onMounted(() => { | ||
| 250 | </el-checkbox-group> | 265 | </el-checkbox-group> |
| 251 | </el-form-item> | 266 | </el-form-item> |
| 252 | <el-form-item style="width: 100%"> | 267 | <el-form-item style="width: 100%"> |
| 253 | - <el-button type="primary" @click="submitForm(ruleFormRef)" | 268 | + <el-button |
| 269 | + type="primary" | ||
| 270 | + @click="submitForm(ruleFormRef)" | ||
| 271 | + :loading="form.loading" | ||
| 254 | >提交</el-button | 272 | >提交</el-button |
| 255 | > | 273 | > |
| 256 | <el-button | 274 | <el-button |
src/views/user/login.vue
| @@ -21,6 +21,8 @@ const loginForm: Login = reactive({ | @@ -21,6 +21,8 @@ const loginForm: Login = reactive({ | ||
| 21 | userName: "", | 21 | userName: "", |
| 22 | password: "", | 22 | password: "", |
| 23 | }); | 23 | }); |
| 24 | + | ||
| 25 | +let loading = ref(false); | ||
| 24 | /** | 26 | /** |
| 25 | * 登录框上面标题 | 27 | * 登录框上面标题 |
| 26 | */ | 28 | */ |
| @@ -30,22 +32,31 @@ const ruleFormRef = ref<InstanceType<typeof ElForm>>(); | @@ -30,22 +32,31 @@ const ruleFormRef = ref<InstanceType<typeof ElForm>>(); | ||
| 30 | * 表单提交 | 32 | * 表单提交 |
| 31 | */ | 33 | */ |
| 32 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { | 34 | const submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => { |
| 35 | + loading.value = true; | ||
| 33 | if (!formEl) return; | 36 | if (!formEl) return; |
| 34 | formEl.validate((valid) => { | 37 | formEl.validate((valid) => { |
| 35 | if (valid) { | 38 | if (valid) { |
| 36 | - login(loginForm).then((res) => { | ||
| 37 | - if (res?.data) { | ||
| 38 | - globalProperties.$message.success("登录成功"); | ||
| 39 | - // 登录成功返回的参数含义,到pinia/modules/login.ts中查看 | ||
| 40 | - store.family.loginStore().setUserInfo(res?.data?.data); | ||
| 41 | - getMenu().then((res) => { | ||
| 42 | - setTimeout(() => { | ||
| 43 | - router.push({ path: "/" }); | ||
| 44 | - }, 1000); | ||
| 45 | - }); | ||
| 46 | - } | ||
| 47 | - }); | 39 | + login(loginForm) |
| 40 | + .then((res) => { | ||
| 41 | + if (res?.data) { | ||
| 42 | + globalProperties.$message.success("登录成功"); | ||
| 43 | + // 登录成功返回的参数含义,到pinia/modules/login.ts中查看 | ||
| 44 | + store.family.loginStore().setUserInfo(res?.data?.data); | ||
| 45 | + getMenu().then((res) => { | ||
| 46 | + setTimeout(() => { | ||
| 47 | + router.push({ path: "/" }); | ||
| 48 | + }, 1000); | ||
| 49 | + }); | ||
| 50 | + } | ||
| 51 | + }) | ||
| 52 | + .catch((error) => { | ||
| 53 | + console.log(error); | ||
| 54 | + }) | ||
| 55 | + .finally(() => { | ||
| 56 | + loading.value = false; | ||
| 57 | + }); | ||
| 48 | } else { | 58 | } else { |
| 59 | + loading.value = false; | ||
| 49 | console.log("error"); | 60 | console.log("error"); |
| 50 | } | 61 | } |
| 51 | }); | 62 | }); |
| @@ -90,7 +101,7 @@ const getMenu = async () => { | @@ -90,7 +101,7 @@ const getMenu = async () => { | ||
| 90 | auto-complete="off" | 101 | auto-complete="off" |
| 91 | clearable | 102 | clearable |
| 92 | :prefix-icon="UserFilled" | 103 | :prefix-icon="UserFilled" |
| 93 | - style="width: 448px;" | 104 | + style="width: 448px" |
| 94 | /> | 105 | /> |
| 95 | </el-form-item> | 106 | </el-form-item> |
| 96 | </el-row> | 107 | </el-row> |
| @@ -115,6 +126,7 @@ const getMenu = async () => { | @@ -115,6 +126,7 @@ const getMenu = async () => { | ||
| 115 | type="primary" | 126 | type="primary" |
| 116 | @click="submitForm(ruleFormRef)" | 127 | @click="submitForm(ruleFormRef)" |
| 117 | style="width: 100%" | 128 | style="width: 100%" |
| 129 | + :loading="loading" | ||
| 118 | >登录</el-button | 130 | >登录</el-button |
| 119 | > | 131 | > |
| 120 | </el-form-item> | 132 | </el-form-item> |