Commit 697dc8ce95cc6102ceb5b339ba3903e3c755a5b1

Authored by 杨泽宇
1 parent 16c7dc0d

图片上传错误拦截,添加返回按钮,401拦截,登录逻辑修复

src/api/request.ts
... ... @@ -8,7 +8,6 @@ let url: any = import.meta.env
8 8 let instance = axios.create({
9 9 baseURL: url.VITE_BASE_URL,
10 10 withCredentials: true,
11   - // timeout: 10
12 11 timeout: 10000
13 12 })
14 13  
... ... @@ -59,11 +58,9 @@ instance.interceptors.response.use(
59 58 return false
60 59 } else {
61 60 msg = error?.message ?? 'Error'
  61 + ElMessage.error(msg);
62 62 return Promise.reject(error)
63 63 }
64   - // console.log(msg)
65   - // ElMessage.error(msg);
66   - // return Promise.reject(error)
67 64 }
68 65 )
69 66  
... ...
src/components/Uploader/index.vue
... ... @@ -88,6 +88,14 @@ const beforeAvatarUpload = (file: ElFile) => {
88 88 }
89 89 return isFormatAllowed && isSizeAllowed;
90 90 };
  91 +/**
  92 + * 上传文件失败回调
  93 + * @param { ElUploadProgressEvent } 回调返回对象
  94 + */
  95 +const handlError = (err: ElUploadProgressEvent) => {
  96 + console.log(err);
  97 + ElMessage.error("上传失败,请重试");
  98 +};
91 99 const emit = defineEmits<{
92 100 (e: "imageChange", url: string, tagName: string): void;
93 101 }>();
... ... @@ -103,6 +111,7 @@ const emit = defineEmits&lt;{
103 111 :headers="uploadSettings.headers"
104 112 name="multipartFile"
105 113 :on-success="handleAvatarSuccess"
  114 + :on-error="handlError"
106 115 :before-upload="beforeAvatarUpload"
107 116 >
108 117 <img
... ...
src/utils/progress.ts
1   -import NProgress from 'nprogress'
2   -import 'nprogress/nprogress.css'
3   -import router from '@/router/index'
  1 +import NProgress from 'nprogress';
  2 +import 'nprogress/nprogress.css';
  3 +import router from '@/router/index';
  4 +import * as store from "@/pinia/index";
4 5  
5   -NProgress.configure({ showSpinner: false })
  6 +NProgress.configure({ showSpinner: false });
6 7  
7 8 router.beforeEach((to: any, from: any, next: any) => {
8   - // if (to.matched.length == 0) { router.push(to.path); }
9   - NProgress.start()
10   - const hasToken = true
11   - const whiteList = ['/login']
  9 + NProgress.start();
  10 + const hasToken = store.family.loginStore().token;
  11 + const whiteList = ['/login'];
12 12  
13   - // TIP 页面标题设置
14   - globalThis.document.title = to.meta.title? to.meta.title: import.meta.env.VITE_APP_TITLE
  13 + // 页面标题设置
  14 + globalThis.document.title = to.meta.title? to.meta.title: import.meta.env.VITE_APP_TITLE;
15 15  
16 16 if (hasToken) {
17   - console.log('has')
18 17 if (to.path === '/login') {
19   - // next({ path: '/about' })
20   - next()
  18 + next({ path: '/dashboard' })
21 19 NProgress.done()
22 20 } else {
23 21 next()
24 22 NProgress.done()
25 23 }
26 24 } else {
27   - console.log('hasnot')
28 25 if (whiteList.indexOf(to.path) !== -1) {
29 26 next()
30 27 } else {
... ...
src/views/permission/edit.vue
... ... @@ -2,6 +2,7 @@
2 2 import { reactive, ref, getCurrentInstance, onMounted } from "vue";
3 3 import { permissionSave } from "@/api/user/permission";
4 4 import { useRoute } from "vue-router";
  5 +import { back } from "@/utils/tool";
5 6 import type { ElForm } from "element-plus";
6 7 let instance: ComponentInternalInstance | null = getCurrentInstance();
7 8 let tempPriority = ref(0);
... ... @@ -175,6 +176,7 @@ onMounted(() =&gt; {
175 176 <el-button type="primary" @click="submitForm(ruleFormRef)"
176 177 >提交</el-button
177 178 >
  179 + <el-button type="info" @click="back">返回</el-button>
178 180 </el-form-item>
179 181 </el-form>
180 182 </el-card>
... ...
src/views/role/edit.vue
... ... @@ -2,6 +2,7 @@
2 2 import { reactive, ref, getCurrentInstance, onMounted } from "vue";
3 3 import { roleSave } from "@/api/user/role";
4 4 import { useRoute } from "vue-router";
  5 +import { back } from "@/utils/tool";
5 6 import type { ElForm } from "element-plus";
6 7 const {
7 8 appContext: {
... ... @@ -105,6 +106,9 @@ onMounted(() =&gt; {
105 106 v-show="form.dataType === 'add'"
106 107 >取消</el-button
107 108 >
  109 + <el-button type="info" @click="back"
  110 + >返回</el-button
  111 + >
108 112 </el-form-item>
109 113 </el-form>
110 114 </el-card>
... ...
src/views/role/permission.vue
... ... @@ -2,9 +2,10 @@
2 2 import { reactive, ref, getCurrentInstance, onMounted } from "vue";
3 3 import { rolePermissionSave, rolePermission } from "@/api/user/role";
4 4 import { useRoute } from "vue-router";
5   -import type Node from 'element-plus/es/components/tree/src/model/node'
  5 +import { back } from "@/utils/tool";
  6 +import type Node from "element-plus/es/components/tree/src/model/node";
6 7 import type { ElForm } from "element-plus";
7   -import type { ElTree } from 'element-plus'
  8 +import type { ElTree } from "element-plus";
8 9 const {
9 10 appContext: {
10 11 config: { globalProperties },
... ... @@ -17,17 +18,17 @@ let form = reactive({
17 18 },
18 19 permissions: [],
19 20 defaultPermissions: [],
20   - collections: []
  21 + collections: [],
21 22 });
22 23 const ruleFormRef = ref<InstanceType<typeof ElForm>>();
23   -const addTreeTest = ref<InstanceType<typeof ElTree>>()
  24 +const addTreeTest = ref<InstanceType<typeof ElTree>>();
24 25 /**
25 26 * 表单重置
26 27 */
27 28 const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => {
28 29 if (!formEl) return;
29   - form.defaultPermissions = []
30   - addTreeTest.value!.setCheckedNodes([])
  30 + form.defaultPermissions = [];
  31 + addTreeTest.value!.setCheckedNodes([]);
31 32 formEl.resetFields();
32 33 };
33 34 /**
... ... @@ -61,14 +62,14 @@ const getPermissions = async (roleId = useRoute().query.roleId) =&gt; {
61 62 try {
62 63 let res = await rolePermission({ roleId: roleId });
63 64 form.permissions = res?.data?.data;
64   - form.defaultPermissions = getCheckedPermissions(res?.data?.data)
  65 + form.defaultPermissions = getCheckedPermissions(res?.data?.data);
65 66 } catch (e) {
66 67 console.log(e);
67 68 }
68 69 };
69 70 interface Tree {
70   - label: string
71   - children?: Tree[]
  71 + label: string;
  72 + children?: Tree[];
72 73 }
73 74 /**
74 75 * 树组件自定义属性
... ... @@ -80,7 +81,7 @@ const defaultProps: Tree = {
80 81 /**
81 82 * 选中树节点回显
82 83 * @param {array} menuArray 树数组
83   - * @returns {array}
  84 + * @returns {array}
84 85 */
85 86 const getCheckedPermissions = (menuArray: Tree[]) => {
86 87 if (menuArray) {
... ... @@ -151,11 +152,10 @@ onMounted(() =&gt; {
151 152 <el-button type="primary" @click="submitForm(ruleFormRef)"
152 153 >提交</el-button
153 154 >
154   - <el-button
155   - type="info"
156   - @click="resetForm(ruleFormRef)"
  155 + <el-button type="info" @click="resetForm(ruleFormRef)"
157 156 >置空</el-button
158 157 >
  158 + <el-button type="info" @click="back">返回</el-button>
159 159 </el-form-item>
160 160 </el-form>
161 161 </el-card>
... ...
src/views/role/user.vue
... ... @@ -2,6 +2,7 @@
2 2 import { reactive, onMounted } from "vue";
3 3 import { useRoute } from 'vue-router';
4 4 import { roleUser } from "@/api/user/role";
  5 +import { back } from '@/utils/tool';
5 6 import Pagination from "@/components/Pagination/index.vue";
6 7 interface Form {
7 8 page: number;
... ... @@ -70,6 +71,9 @@ onMounted(() =&gt; {
70 71 <template>
71 72 <div class="page-container">
72 73 <h1>角色用户</h1>
  74 + <el-row style="padding-bottom: 20px">
  75 + <el-button type="info" @click="back">返回</el-button>
  76 + </el-row>
73 77 <el-table
74 78 :data="data.list"
75 79 style="width: 100%"
... ...
src/views/user/role.vue
1 1 <script setup lang="ts">
2 2 import { reactive, ref, onMounted } from "vue";
3 3 import { userRoles } from "@/api/user/user";
4   -import { parseTime } from "@/utils/tool";
  4 +import { parseTime, back } from "@/utils/tool";
5 5 import { useRoute } from "vue-router";
6 6 interface Form {
7 7 page: number;
... ... @@ -49,6 +49,9 @@ onMounted(() =&gt; {
49 49 <template>
50 50 <div class="page-container">
51 51 <h1>用户角色</h1>
  52 + <el-row style="padding-bottom: 20px">
  53 + <el-button type="info" @click="back">返回</el-button>
  54 + </el-row>
52 55 <el-table
53 56 :data="data.list"
54 57 style="width: 100%"
... ...