Browse Source

feat: 接口初次对接-CORS

ystl_myq 8 months ago
parent
commit
3b6606790a

+ 2 - 0
.env.development

@@ -6,3 +6,5 @@ VITE_PUBLIC_PATH = /
 
 # 开发环境路由历史模式(Hash模式传"hash"、HTML5模式传"h5"、Hash模式带base参数传"hash,base参数"、HTML5模式带base参数传"h5,base参数")
 VITE_ROUTER_HISTORY = "hash"
+
+VITE_BASE_URL = "http://116.148.231.158:9087"

+ 4 - 0
src/api/system.ts

@@ -0,0 +1,4 @@
+import { http } from "@/utils/http";
+export const addDeptPost = (data?) => {
+  return http.request("post", "/sysDept/addDept", { data });
+};

+ 4 - 1
src/api/user.ts

@@ -1,5 +1,5 @@
 import { http } from "@/utils/http";
-
+// import { baseUrlApi } from "./utils";
 export type UserResult = {
   success: boolean;
   data: {
@@ -29,6 +29,9 @@ export type RefreshTokenResult = {
 };
 
 /** 登录 */
+// export const getLogin = (data?: object) => {
+//   return http.request<UserResult>("post", baseUrlApi("/user/login"), { data });
+// };
 export const getLogin = (data?: object) => {
   return http.request<UserResult>("post", "/login", { data });
 };

+ 1 - 0
src/api/utils.ts

@@ -0,0 +1 @@
+export const baseUrlApi = (url: string) => `/api/${url}`;

+ 1 - 0
src/utils/http/index.ts

@@ -18,6 +18,7 @@ import { useUserStoreHook } from "@/store/modules/user";
 const defaultConfig: AxiosRequestConfig = {
   // 请求超时时间
   timeout: 10000,
+  // baseURL: import.meta.env.VITE_BASE_URL,
   headers: {
     Accept: "application/json, text/plain, */*",
     "Content-Type": "application/json",

+ 6 - 0
src/views/background/framework/proson/prosonDepartment.vue

@@ -10,6 +10,7 @@ import newDepartment from "./components/newDepartment.vue";
 import addPerson from "./components/addPerson.vue";
 import personDetailsDrawer from "./components/personDetailsDrawer.vue";
 import changeRole from "./components/changeRole.vue";
+import { addDeptPost } from "@/api/system.ts";
 // 添加部门
 const newDepartmentRef = ref(null);
 const newDepartmentShow = ref(false);
@@ -108,6 +109,11 @@ const tableData = [
 const addDepartment = () => {
   newDepartmentRef.value.open();
 };
+const addDeptPostApi = async () => {
+  let res = await addDeptPost();
+  console.log(res);
+};
+// addDeptPostApi();
 // 删除人员
 const deletePerson = row => {
   console.log(row);

+ 3 - 0
src/views/indexDefine/children/define.vue

@@ -121,13 +121,16 @@ const GoSizeImport = () => {
 
 <template>
   <div>
+    <!-- 批量导入 -->
     <IndexDefineImport v-if="sizeImport" @handleImport="GoSizeImport" />
     <div v-else>
+      <!-- 指标详情 -->
       <editDrawer ref="EditdrawerShow" v-model:drawerValue="EditshowDrawer" />
       <DetailsDrawer
         ref="DetailsdrawerShow"
         v-model:drawerValue="DetailsshowDrawer"
       />
+      <!-- 新建 -->
       <dialogVue
         ref="dialogShow"
         v-model:modelValue="showDialog"

+ 6 - 3
src/views/login/index.vue

@@ -33,8 +33,8 @@ dataThemeChange();
 const { title } = useNav();
 
 const ruleForm = reactive({
-  username: "admin",
-  password: "admin123"
+  username: "",
+  password: ""
 });
 
 const onLogin = async (formEl: FormInstance | undefined) => {
@@ -43,7 +43,10 @@ const onLogin = async (formEl: FormInstance | undefined) => {
   await formEl.validate((valid, fields) => {
     if (valid) {
       useUserStoreHook()
-        .loginByUsername({ username: ruleForm.username, password: "admin123" })
+        .loginByUsername({
+          username: ruleForm.username,
+          password: ruleForm.password
+        })
         .then(res => {
           if (res.success) {
             // 获取后端路由

+ 9 - 7
src/views/login/utils/rule.ts

@@ -2,8 +2,8 @@ import { reactive } from "vue";
 import type { FormRules } from "element-plus";
 
 /** 密码正则(密码格式应为8-18位数字、字母、符号的任意两种组合) */
-export const REGEXP_PWD =
-  /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){8,18}$/;
+// export const REGEXP_PWD =
+//   /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){6,18}$/;
 
 /** 登录校验 */
 const loginRules = reactive(<FormRules>{
@@ -12,11 +12,13 @@ const loginRules = reactive(<FormRules>{
       validator: (rule, value, callback) => {
         if (value === "") {
           callback(new Error("请输入密码"));
-        } else if (!REGEXP_PWD.test(value)) {
-          callback(
-            new Error("密码格式应为8-18位数字、字母、符号的任意两种组合")
-          );
-        } else {
+        }
+        // else if (!REGEXP_PWD.test(value)) {
+        //   callback(
+        //     new Error("密码格式应为6-18位数字、字母、符号的任意两种组合")
+        //   );
+        // }
+        else {
           callback();
         }
       },

+ 8 - 1
vite.config.ts

@@ -24,7 +24,14 @@ export default ({ mode }: ConfigEnv): UserConfigExport => {
       port: VITE_PORT,
       host: "0.0.0.0",
       // 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
-      proxy: {},
+      proxy: {
+        "/api": {
+          // 这里填写后端地址
+          target: "http://116.148.231.158:9087",
+          changeOrigin: true,
+          rewrite: path => path.replace(/^\/api/, "")
+        }
+      },
       // 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
       warmup: {
         clientFiles: ["./index.html", "./src/{views,components}/*"]