mirror of
https://github.com/certd/certd.git
synced 2026-04-16 14:00:51 +08:00
pref: 优化插件store
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
import { request } from "../service";
|
||||
|
||||
export type SiteEnv = {
|
||||
agent?: {
|
||||
enabled?: boolean;
|
||||
contactText?: string;
|
||||
contactLink?: string;
|
||||
};
|
||||
};
|
||||
export type AppInfo = {
|
||||
version?: string;
|
||||
time?: number;
|
||||
deltaTime?: number;
|
||||
};
|
||||
export type SiteInfo = {
|
||||
title?: string;
|
||||
slogan?: string;
|
||||
logo?: string;
|
||||
loginLogo?: string;
|
||||
icpNo?: string;
|
||||
licenseTo?: string;
|
||||
licenseToUrl?: string;
|
||||
};
|
||||
|
||||
export type PlusInfo = {
|
||||
vipType?: string;
|
||||
expireTime?: number;
|
||||
isPlus: boolean;
|
||||
isComm?: boolean;
|
||||
};
|
||||
export type SysPublicSetting = {
|
||||
registerEnabled?: boolean;
|
||||
usernameRegisterEnabled?: boolean;
|
||||
mobileRegisterEnabled?: boolean;
|
||||
emailRegisterEnabled?: boolean;
|
||||
passwordLoginEnabled?: boolean;
|
||||
smsLoginEnabled?: boolean;
|
||||
|
||||
limitUserPipelineCount?: number;
|
||||
managerOtherUserPipeline?: boolean;
|
||||
icpNo?: string;
|
||||
robots?: boolean;
|
||||
};
|
||||
export type SuiteSetting = {
|
||||
enabled?: boolean;
|
||||
};
|
||||
export type SysPrivateSetting = {
|
||||
httpProxy?: string;
|
||||
httpsProxy?: string;
|
||||
dnsResultOrder?: string;
|
||||
commonCnameEnabled?: boolean;
|
||||
sms?: {
|
||||
type?: string;
|
||||
config?: any;
|
||||
};
|
||||
};
|
||||
export type SysInstallInfo = {
|
||||
siteId: string;
|
||||
};
|
||||
export type MenuItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
icon?: string;
|
||||
path?: string;
|
||||
children?: MenuItem[];
|
||||
};
|
||||
export type HeaderMenus = {
|
||||
menus: MenuItem[];
|
||||
};
|
||||
|
||||
export type AllSettings = {
|
||||
sysPublic: SysPublicSetting;
|
||||
installInfo: SysInstallInfo;
|
||||
plusInfo: PlusInfo;
|
||||
siteInfo: SiteInfo;
|
||||
siteEnv: SiteEnv;
|
||||
headerMenus: HeaderMenus;
|
||||
suiteSetting: SuiteSetting;
|
||||
app: AppInfo;
|
||||
};
|
||||
|
||||
export async function loadAllSettings(): Promise<AllSettings> {
|
||||
return await request({
|
||||
url: "/basic/settings/all",
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
export async function bindUrl(data: any): Promise<any> {
|
||||
return await request({
|
||||
url: "/sys/plus/bindUrl",
|
||||
method: "post",
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendSmsCode(data: any): Promise<any> {
|
||||
return await request({
|
||||
url: "/basic/code/sendSmsCode",
|
||||
method: "post",
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendEmailCode(data: any): Promise<any> {
|
||||
return await request({
|
||||
url: "/basic/code/sendEmailCode",
|
||||
method: "post",
|
||||
data,
|
||||
});
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
export default [
|
||||
{
|
||||
path: "/login",
|
||||
method: "post",
|
||||
handle() {
|
||||
return {
|
||||
code: 0,
|
||||
msg: "success",
|
||||
data: {
|
||||
token: "faker token",
|
||||
expire: 10000
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/sys/authority/user/mine",
|
||||
method: "get",
|
||||
handle() {
|
||||
return {
|
||||
code: 0,
|
||||
msg: "success",
|
||||
data: {
|
||||
id: 1,
|
||||
username: "username",
|
||||
nickName: "admin"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
];
|
||||
@@ -1,84 +0,0 @@
|
||||
import { request, requestForMock } from "../service";
|
||||
import { env } from "/@/utils/util.env";
|
||||
|
||||
export interface RegisterReq {
|
||||
username: string;
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
/**
|
||||
* @description: Login interface parameters
|
||||
*/
|
||||
export interface LoginReq {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface SmsLoginReq {
|
||||
mobile: string;
|
||||
phoneCode: string;
|
||||
smsCode: string;
|
||||
randomStr: string;
|
||||
}
|
||||
|
||||
export interface UserInfoRes {
|
||||
id: string | number;
|
||||
username: string;
|
||||
nickName: string;
|
||||
avatar?: string;
|
||||
roleIds: number[];
|
||||
isWeak?: boolean;
|
||||
}
|
||||
|
||||
export interface LoginRes {
|
||||
token: string;
|
||||
expire: number;
|
||||
}
|
||||
|
||||
export async function register(user: RegisterReq): Promise<UserInfoRes> {
|
||||
return await request({
|
||||
url: "/register",
|
||||
method: "post",
|
||||
data: user
|
||||
});
|
||||
}
|
||||
|
||||
export async function login(data: LoginReq): Promise<LoginRes> {
|
||||
if (env.PM_ENABLED === "false") {
|
||||
//没有开启权限模块,模拟登录
|
||||
return await requestForMock({
|
||||
url: "/login",
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
}
|
||||
//如果开启了登录与权限模块,则真实登录
|
||||
return await request({
|
||||
url: "/login",
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
export async function loginBySms(data: SmsLoginReq): Promise<LoginRes> {
|
||||
//如果开启了登录与权限模块,则真实登录
|
||||
return await request({
|
||||
url: "/loginBySms",
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
export async function mine(): Promise<UserInfoRes> {
|
||||
if (env.PM_ENABLED === "false") {
|
||||
//没有开启权限模块,模拟登录
|
||||
return await requestForMock({
|
||||
url: "/sys/authority/user/mine",
|
||||
method: "post"
|
||||
});
|
||||
}
|
||||
return await request({
|
||||
url: "/mine/info",
|
||||
method: "post"
|
||||
});
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import axios from "axios";
|
||||
import { get } from "lodash-es";
|
||||
import Adapter from "axios-mock-adapter";
|
||||
import { errorLog, errorCreate, response } from "./tools";
|
||||
import { errorLog, errorCreate } from "./tools";
|
||||
import { env } from "/src/utils/util.env";
|
||||
import { useUserStore } from "../store/modules/user";
|
||||
import { useUserStore } from "/@/store/user";
|
||||
/**
|
||||
* @description 创建请求实例
|
||||
*/
|
||||
@@ -12,8 +11,8 @@ function createService() {
|
||||
const service = axios.create();
|
||||
// 请求拦截
|
||||
service.interceptors.request.use(
|
||||
(config) => config,
|
||||
(error) => {
|
||||
config => config,
|
||||
error => {
|
||||
// 发送失败
|
||||
console.log(error);
|
||||
return Promise.reject(error);
|
||||
@@ -21,7 +20,7 @@ function createService() {
|
||||
);
|
||||
// 响应拦截
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
response => {
|
||||
if (response.config.responseType === "blob") {
|
||||
return response;
|
||||
}
|
||||
@@ -67,7 +66,7 @@ function createService() {
|
||||
}
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
const status = get(error, "response.status");
|
||||
switch (status) {
|
||||
case 400:
|
||||
@@ -130,11 +129,11 @@ function createRequestFunction(service: any) {
|
||||
return function (config: any) {
|
||||
const configDefault = {
|
||||
headers: {
|
||||
"Content-Type": get(config, "headers.Content-Type", "application/json")
|
||||
"Content-Type": get(config, "headers.Content-Type", "application/json"),
|
||||
},
|
||||
timeout: 20000,
|
||||
baseURL: env.API,
|
||||
data: {}
|
||||
data: {},
|
||||
};
|
||||
const userStore = useUserStore();
|
||||
const token = userStore.getToken;
|
||||
@@ -149,10 +148,3 @@ function createRequestFunction(service: any) {
|
||||
// 用于真实网络请求的实例和请求方法
|
||||
export const service = createService();
|
||||
export const request = createRequestFunction(service);
|
||||
|
||||
// 用于模拟网络请求的实例和请求方法
|
||||
export const serviceForMock = createService();
|
||||
export const requestForMock = createRequestFunction(serviceForMock);
|
||||
|
||||
// 网络请求数据模拟工具
|
||||
export const mock = new Adapter(serviceForMock, { delayResponse: 200 });
|
||||
|
||||
Reference in New Issue
Block a user