diff --git a/admin/src/api/users.ts b/admin/src/api/users.ts index b8a76f33..b0db4422 100644 --- a/admin/src/api/users.ts +++ b/admin/src/api/users.ts @@ -22,3 +22,31 @@ export function usersintegralListApi(params?: any) { export function accountLog(params?: any) { return request.get({ url: "/user.user/lists", params }); } +// 省 +export function proApi(params?: any) { + return request.get({ url: "/geo/provinces", params }); +} +// 市 +export function cityApi(params?: any) { + return request.get({ url: "/geo/cities", params }); +} +// 区 +export function areaApi(params?: any) { + return request.get({ url: "/geo/areas", params }); +} +// 镇 +export function townApi(params?: any) { + return request.get({ url: "/geo/streets", params }); +} +// 村 +export function coutnyApi(params?: any) { + return request.get({ url: "/geo/villages", params }); +} +// 组 +export function groupApi(params?: any) { + return request.get({ url: "/geo/brigades", params }); +} +// apps +export function appListApi(params?: any) { + return request.get({ url: "/user.user/apps", params }); +} diff --git a/admin/src/config/index.ts b/admin/src/config/index.ts index 1eabdb33..51c8e39a 100644 --- a/admin/src/config/index.ts +++ b/admin/src/config/index.ts @@ -1,10 +1,20 @@ +// const config = { +// terminal: 1, //终端 +// title: "后台管理系统", //网站默认标题 +// version: "1.6.0", //版本号 +// baseUrl: `${ +// import.meta.env.VITE_APP_BASE_URL || "https://ceshi-middle.lihaink.cn/" +// }/`, //请求接口域名 +// urlPrefix: "adminapi", //请求默认前缀 +// timeout: 10 * 1000, //请求超时时长 +// }; + +// export default config; const config = { terminal: 1, //终端 title: "后台管理系统", //网站默认标题 version: "1.6.0", //版本号 - baseUrl: `${ - import.meta.env.VITE_APP_BASE_URL || "" - }/`, //请求接口域名 + baseUrl: " ", //请求接口域名 urlPrefix: "adminapi", //请求默认前缀 timeout: 10 * 1000, //请求超时时长 }; diff --git a/admin/src/utils/request/index.ts b/admin/src/utils/request/index.ts index e66915d2..dcb689c8 100644 --- a/admin/src/utils/request/index.ts +++ b/admin/src/utils/request/index.ts @@ -1,123 +1,129 @@ -import { merge } from 'lodash' -import configs from '@/config' -import { Axios } from './axios' -import { ContentTypeEnum, RequestCodeEnum, RequestMethodsEnum } from '@/enums/requestEnums' -import type { AxiosHooks } from './type' -import { clearAuthInfo, getToken } from '../auth' -import feedback from '../feedback' -import NProgress from 'nprogress' -import { AxiosError, type AxiosRequestConfig } from 'axios' -import router from '@/router' -import { PageEnum } from '@/enums/pageEnum' - +import { merge } from "lodash"; +import configs from "@/config"; +import { Axios } from "./axios"; +import { + ContentTypeEnum, + RequestCodeEnum, + RequestMethodsEnum, +} from "@/enums/requestEnums"; +import type { AxiosHooks } from "./type"; +import { clearAuthInfo, getToken } from "../auth"; +import feedback from "../feedback"; +import NProgress from "nprogress"; +import { AxiosError, type AxiosRequestConfig } from "axios"; +import router from "@/router"; +import { PageEnum } from "@/enums/pageEnum"; +// console.log(configs.baseUrl, "bseurl"); // 处理axios的钩子函数 const axiosHooks: AxiosHooks = { - requestInterceptorsHook(config) { - NProgress.start() - const { withToken, isParamsToData } = config.requestOptions - const params = config.params || {} - const headers = config.headers || {} + requestInterceptorsHook(config) { + NProgress.start(); + const { withToken, isParamsToData } = config.requestOptions; + const params = config.params || {}; + const headers = config.headers || {}; - // 添加token - if (withToken) { - const token = getToken() - headers.token = token - } - // POST请求下如果无data,则将params视为data - if ( - isParamsToData && - !Reflect.has(config, 'data') && - config.method?.toUpperCase() === RequestMethodsEnum.POST - ) { - config.data = params - config.params = {} - } - config.headers = headers - return config - }, - requestInterceptorsCatchHook(err) { - NProgress.done() - return err - }, - async responseInterceptorsHook(response) { - NProgress.done() - const { isTransformResponse, isReturnDefaultResponse } = response.config.requestOptions - - //返回默认响应,当需要获取响应头及其他数据时可使用 - if (isReturnDefaultResponse) { - return response - } - // 是否需要对数据进行处理 - if (!isTransformResponse) { - return response.data - } - const { code, data, show, msg } = response.data - switch (code) { - case RequestCodeEnum.SUCCESS: - if (show) { - msg && feedback.msgSuccess(msg) - } - return data - case RequestCodeEnum.FAIL: - if (show) { - msg && feedback.msgError(msg) - } - return Promise.reject(data) - case RequestCodeEnum.LOGIN_FAILURE: - clearAuthInfo() - router.push(PageEnum.LOGIN) - return Promise.reject() - case RequestCodeEnum.OPEN_NEW_PAGE: - window.location.href = data.url - return data - default: - return data - } - }, - responseInterceptorsCatchHook(error) { - NProgress.done() - if (error.code !== AxiosError.ERR_CANCELED) { - error.message && feedback.msgError(error.message) - } - return Promise.reject(error) + // 添加token + if (withToken) { + const token = getToken(); + headers.token = token; } -} + // POST请求下如果无data,则将params视为data + if ( + isParamsToData && + !Reflect.has(config, "data") && + config.method?.toUpperCase() === RequestMethodsEnum.POST + ) { + config.data = params; + config.params = {}; + } + config.headers = headers; + return config; + }, + requestInterceptorsCatchHook(err) { + NProgress.done(); + return err; + }, + async responseInterceptorsHook(response) { + NProgress.done(); + const { isTransformResponse, isReturnDefaultResponse } = + response.config.requestOptions; + + //返回默认响应,当需要获取响应头及其他数据时可使用 + if (isReturnDefaultResponse) { + return response; + } + // 是否需要对数据进行处理 + if (!isTransformResponse) { + return response.data; + } + const { code, data, show, msg } = response.data; + switch (code) { + case RequestCodeEnum.SUCCESS: + if (show) { + msg && feedback.msgSuccess(msg); + } + return data; + case RequestCodeEnum.FAIL: + if (show) { + msg && feedback.msgError(msg); + } + return Promise.reject(data); + case RequestCodeEnum.LOGIN_FAILURE: + clearAuthInfo(); + router.push(PageEnum.LOGIN); + return Promise.reject(); + case RequestCodeEnum.OPEN_NEW_PAGE: + window.location.href = data.url; + return data; + default: + return data; + } + }, + responseInterceptorsCatchHook(error) { + NProgress.done(); + if (error.code !== AxiosError.ERR_CANCELED) { + error.message && feedback.msgError(error.message); + } + return Promise.reject(error); + }, +}; const defaultOptions: AxiosRequestConfig = { - //接口超时时间 - timeout: configs.timeout, - // 基础接口地址 - baseURL: configs.baseUrl, - //请求头 - headers: { 'Content-Type': ContentTypeEnum.JSON, version: configs.version }, - // 处理 axios的钩子函数 - axiosHooks: axiosHooks, - // 每个接口可以单独配置 - requestOptions: { - // 是否将params视为data参数,仅限post请求 - isParamsToData: true, - //是否返回默认的响应 - isReturnDefaultResponse: false, - // 需要对返回数据进行处理 - isTransformResponse: true, - // 接口拼接地址 - urlPrefix: configs.urlPrefix, - // 忽略重复请求 - ignoreCancelToken: false, - // 是否携带token - withToken: true, - // 开启请求超时重新发起请求请求机制 - isOpenRetry: true, - // 重新请求次数 - retryCount: 2 - } -} + //接口超时时间 + timeout: configs.timeout, + // 基础接口地址 + baseURL: configs.baseUrl, + //请求头 + headers: { "Content-Type": ContentTypeEnum.JSON, version: configs.version }, + // 处理 axios的钩子函数 + axiosHooks: axiosHooks, + // 每个接口可以单独配置 + requestOptions: { + // 是否将params视为data参数,仅限post请求 + isParamsToData: true, + //是否返回默认的响应 + isReturnDefaultResponse: false, + // 需要对返回数据进行处理 + isTransformResponse: true, + // 接口拼接地址 + urlPrefix: configs.urlPrefix, + // 忽略重复请求 + ignoreCancelToken: false, + // 是否携带token + withToken: true, + // 开启请求超时重新发起请求请求机制 + isOpenRetry: true, + // 重新请求次数 + retryCount: 2, + }, +}; function createAxios(opt?: Partial) { - return new Axios( - // 深度合并 - merge(defaultOptions, opt || {}) - ) + return new Axios( + // 深度合并 + merge(defaultOptions, opt || {}) + ); } -const request = createAxios() -export default request +const request = createAxios(); +console.log(request, "requ"); +export default request; diff --git a/admin/src/views/systems/list.vue b/admin/src/views/systems/list.vue index 5ba728c6..09ac54f5 100644 --- a/admin/src/views/systems/list.vue +++ b/admin/src/views/systems/list.vue @@ -1,5 +1,5 @@