fix: 状态码使用常量避免后续变更

This commit is contained in:
TsMask
2023-09-14 15:19:37 +08:00
parent 9a88d9b8de
commit 03e1b4b8bd
18 changed files with 120 additions and 78 deletions

View File

@@ -1,5 +1,6 @@
import { defineStore } from 'pinia';
import { getDictDataType } from '@/api/system/dict/data';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
/**字典参数类型 */
type DictStore = {
@@ -42,7 +43,7 @@ const useDictStore = defineStore('dict', {
let disct = this.dicts.get(key);
if (disct === undefined || disct.length === 0) {
const res = await getDictDataType(key);
if (res.code === 1 && Array.isArray(res.data)) {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
const dictData: DictType[] = res.data.map(d => ({
label: d.dictLabel,
value: d.dictValue,

View File

@@ -14,6 +14,7 @@ import {
MENU_COMPONENT_LAYOUT_BLANK,
MENU_COMPONENT_LAYOUT_LINK,
} from '@/constants/menu-constants';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
/**路由构建参数类型 */
type RouterStore = {
@@ -46,7 +47,7 @@ const useRouterStore = defineStore('router', {
*/
async generateRoutes() {
const res = await getRouters();
if (res.code === 1 && Array.isArray(res.data)) {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
const buildRoutes = buildRouters(res.data.concat());
this.buildRouterData = buildRoutes;
return buildRoutes;

View File

@@ -5,6 +5,7 @@ import { getToken, setToken, removeToken } from '@/plugins/auth-token';
import { defineStore } from 'pinia';
import { TOKEN_RESPONSE_FIELD } from '@/constants/token-constants';
import { validHttp } from '@/utils/regular-utils';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
/**用户信息类型 */
type UserInfo = {
@@ -107,7 +108,7 @@ const useUserStore = defineStore('user', {
// 登录
async fnLogin(loginBody: Record<string, string>) {
const res = await login(loginBody);
if (res.code === 1 && res.data) {
if (res.code === RESULT_CODE_SUCCESS && res.data) {
const token = res.data[TOKEN_RESPONSE_FIELD];
setToken(token);
this.token = token;
@@ -117,7 +118,7 @@ const useUserStore = defineStore('user', {
// 获取用户信息
async fnGetInfo() {
const res = await getInfo();
if (res.code === 1 && res.data) {
if (res.code === RESULT_CODE_SUCCESS && res.data) {
const { user, roles, permissions } = res.data;
// 登录账号
this.userName = user.accountId;