浏览代码

feat: change login

奇橙 1 年之前
父节点
当前提交
501587c1d7
共有 5 个文件被更改,包括 161 次插入298 次删除
  1. 14 48
      src/ajax/api/user.js
  2. 39 39
      src/ajax/request.js
  3. 90 82
      src/components/DialogFeedback.vue
  4. 1 1
      src/components/DocumentCards.vue
  5. 17 128
      src/views/Login.vue

+ 14 - 48
src/ajax/api/user.js

@@ -1,63 +1,29 @@
-import request from '../request';
+import request from "../request";
 
 /**
  * 获取用户信息
  * @returns {Promise<Object>}
  */
 const getInfo = () => {
-  return request.get('/app-api/member/user/get');
+    return request.get("/app-api/member/user/get");
 };
 
 /**
- * 发送验证码
- * @param {string} mobile - 手机号
+ * 登录
+ * @param {string} username
+ * @param {string} password
  * @returns {Promise<Object>}
  */
-const sendSms = (mobile) => {
-  return request.post('/app-api/member/auth/send-sms-code', {
-    mobile: String(mobile),
-    scene: 1
-  });
-};
-
-/**
- * 退出登录
- * @returns {Promise<Object>}
- */
-const loginOut = () => {
-  return request.post('/app-api/member/auth/logout');
-};
-
-/**
- * 验证码登录
- * @param {string} mobile - 手机号
- * @param {string} code - 验证码
- * @returns {Promise<Object>}
- */
-const smsLogin = (mobile, code) => {
-  return request.post('/app-api/member/auth/sms-login', {
-    mobile: String(mobile),
-    code: String(code)
-  });
-};
-
-/**
- * 刷新令牌
- * @param {string} token - token
- * @returns {Promise<Object>}
- */
-const refreshToken = (token) => {
-  return request.post('/app-api/member/auth/refresh-token', {}, {
-    params: {
-      refreshToken: token
-    }
-  });
+const login = (username, password) => {
+    return request.post("/api/auth/login", {
+        params: {
+            username,
+            password
+        }
+    });
 };
 
 export default {
-  sendSms,
-  smsLogin,
-  getInfo,
-  loginOut,
-  refreshToken
+    login,
+    getInfo
 };

+ 39 - 39
src/ajax/request.js

@@ -1,28 +1,28 @@
-import axios from 'axios';
-import ArcoVue from '@arco-design/web-vue';
-import helper from '@/utils/helper';
+import axios from "axios";
+import ArcoVue from "@arco-design/web-vue";
+import helper from "@/utils/helper";
 const service = axios.create({
-  baseURL: 'http://47.121.215.37:48080',
-  withCredentials: true, // 跨域发送 cookie
-  timeout: 3000, // 请求超时
-  headers: {
-    'tenant-id': '162',
-    'Content-Type': 'application/json'
-  },
+    baseURL: "http://smartai.com:8000",
+    withCredentials: true, // 跨域发送 cookie
+    timeout: 3000, // 请求超时
+    headers: {
+        "tenant-id": "162",
+        "Content-Type": "application/json"
+    }
 });
 service.interceptors.request.use(
-  (config) => {
-    if (window.localStorage.tokenMap) {
-      config.headers['Authorization'] = JSON.parse(window.localStorage.tokenMap).accessToken;
+    (config) => {
+        if (window.localStorage.tokenMap) {
+            config.headers["Authorization"] = JSON.parse(window.localStorage.tokenMap).accessToken;
+        }
+        helper.setLoading(true);
+        return config;
+    },
+    (error) => {
+        console.error(error);
+        // 请求出错
+        return Promise.reject(error);
     }
-    helper.setLoading(true);
-    return config;
-  },
-  (error) => {
-    console.error(error);
-    // 请求出错
-    return Promise.reject(error);
-  },
 );
 
 /**
@@ -30,7 +30,7 @@ service.interceptors.request.use(
  * @param {*} response
  */
 const handlerLogin = (response) => {
-  if (response?.status !== 401 && response?.data?.msg !== '没有登录') return response;
+    if (response?.status !== 401 && response?.data?.msg !== "没有登录") return response;
 };
 
 /**
@@ -38,27 +38,27 @@ const handlerLogin = (response) => {
  * @param {*} response
  */
 const handler403 = (response) => {
-  if (response?.status !== 403) return response;
+    if (response?.status !== 403) return response;
 };
 
 service.interceptors.response.use(
-  (response) => {
-    const { code, data, msg } = response.data;
-    helper.setLoading(false);
-    if (code === 0) {
-      return data;
-    } else {
-      ArcoVue.Message['error']({content: msg, duration: 1500 });
-      return false;
+    (response) => {
+        const { code, data, msg } = response.data;
+        helper.setLoading(false);
+        if (code === 0) {
+            return data;
+        } else {
+            ArcoVue.Message["error"]({ content: msg, duration: 1500 });
+            return false;
+        }
+    },
+    (error) => {
+        handlerLogin(error.response);
+        handler403(error.response);
+        helper.setLoading(false);
+        ArcoVue.Message["error"]({ content: `网络异常,请稍后重试`, duration: 1500 });
+        // return false;
     }
-  },
-  (error) => {
-    handlerLogin(error.response);
-    handler403(error.response);
-    helper.setLoading(false);
-    ArcoVue.Message['error']({content: `网络异常,请稍后重试`, duration: 1500 });
-    // return false;
-  },
 );
 
 export default service;

+ 90 - 82
src/components/DialogFeedback.vue

@@ -1,94 +1,102 @@
 <template>
-  <a-modal v-model:visible="showFeedback" @beforeOk="handleOk" @beforeCancel="handleCancel" okText="提交">
-    <template #title>
-      进一步反馈
-    </template>
-    <p class="feedback-title">理解问题有误</p>
-    <a-checkbox-group v-model="feedbackValue1" class="feedback-content">
-      <a-grid :cols="2" :colGap="10" :rowGap="8">
-        <a-grid-item>
-          <a-checkbox value="1">没能理解指令</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="2">未发现问题中的错误</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="3">无法理解上下文</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="4">答非所问</a-checkbox>
-        </a-grid-item>
-      </a-grid>
-    </a-checkbox-group>
-    <p class="feedback-title">回答不佳</p>
-    <a-checkbox-group v-model="feedbackValue2" class="feedback-content">
-      <a-grid :cols="2" :colGap="10" :rowGap="8">
-        <a-grid-item>
-          <a-checkbox value="1">有事实性错误</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="2">回答重复</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="3">格式错误</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="4">对我没帮助</a-checkbox>
-        </a-grid-item>
-      </a-grid>
-    </a-checkbox-group>
-    <p class="feedback-title">有害信息</p>
-    <a-checkbox-group v-model="feedbackValue3" class="feedback-content">
-      <a-grid :cols="2" :colGap="10" :rowGap="8">
-        <a-grid-item>
-          <a-checkbox value="1">敏感/有害回复</a-checkbox>
-        </a-grid-item>
-        <a-grid-item>
-          <a-checkbox value="2">存在价值观问题</a-checkbox>
-        </a-grid-item>
-      </a-grid>
-    </a-checkbox-group>
-    <p class="feedback-title">你认为更理想的答复是什么?</p>
-    <a-textarea v-model="feedbackValue4" :style="{width:'100%',height:'100px',border: '1px solid rgba(187, 187, 187, 1)',background:'rgba(0,0,0,0)'}" auto-size placeholder="请输入" allow-clear />
-  </a-modal>
+    <a-modal v-model:visible="showFeedback" @beforeOk="handleOk" @beforeCancel="handleCancel" okText="提交">
+        <template #title> 进一步反馈 </template>
+        <p class="feedback-title">理解问题有误</p>
+        <a-checkbox-group v-model="feedbackValue1" class="feedback-content">
+            <a-grid :cols="2" :colGap="10" :rowGap="8">
+                <a-grid-item>
+                    <a-checkbox value="1">没能理解指令</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="2">未发现问题中的错误</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="3">无法理解上下文</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="4">答非所问</a-checkbox>
+                </a-grid-item>
+            </a-grid>
+        </a-checkbox-group>
+        <p class="feedback-title">回答不佳</p>
+        <a-checkbox-group v-model="feedbackValue2" class="feedback-content">
+            <a-grid :cols="2" :colGap="10" :rowGap="8">
+                <a-grid-item>
+                    <a-checkbox value="1">有事实性错误</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="2">回答重复</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="3">格式错误</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="4">对我没帮助</a-checkbox>
+                </a-grid-item>
+            </a-grid>
+        </a-checkbox-group>
+        <p class="feedback-title">有害信息</p>
+        <a-checkbox-group v-model="feedbackValue3" class="feedback-content">
+            <a-grid :cols="2" :colGap="10" :rowGap="8">
+                <a-grid-item>
+                    <a-checkbox value="1">敏感/有害回复</a-checkbox>
+                </a-grid-item>
+                <a-grid-item>
+                    <a-checkbox value="2">存在价值观问题</a-checkbox>
+                </a-grid-item>
+            </a-grid>
+        </a-checkbox-group>
+        <p class="feedback-title">你认为更理想的答复是什么?</p>
+        <a-textarea
+            v-model="feedbackValue4"
+            :style="{
+                width: '100%',
+                height: '100px',
+                border: '1px solid rgba(187, 187, 187, 1)',
+                background: 'rgba(0,0,0,0)'
+            }"
+            auto-size
+            placeholder="请输入"
+            allow-clear
+        />
+    </a-modal>
 </template>
 <script>
-import { defineComponent, ref } from 'vue';
+import { defineComponent, ref } from "vue";
 export default defineComponent({
-  components: {
-  },
-  props: ['showFeedback'],
-  setup(props, {emit}) {
-    const feedbackValue1 = ref([]);
-    const feedbackValue2 = ref([]);
-    const feedbackValue3 = ref([]);
-    const feedbackValue4 = ref('');
-    const handleOk = () => {
-      emit('handle-ok');
-      return false;
-    };
-    const handleCancel = () => {
-      emit('handle-cancel');
-      return false;
+    components: {},
+    props: ["showFeedback"],
+    setup(props, { emit }) {
+        const feedbackValue1 = ref([]);
+        const feedbackValue2 = ref([]);
+        const feedbackValue3 = ref([]);
+        const feedbackValue4 = ref("");
+        const handleOk = () => {
+            emit("handle-ok");
+            return false;
+        };
+        const handleCancel = () => {
+            emit("handle-cancel");
+            return false;
+        };
+        return {
+            feedbackValue1,
+            feedbackValue2,
+            feedbackValue3,
+            feedbackValue4,
+            handleOk,
+            handleCancel
+        };
     }
-    return {
-      feedbackValue1,
-      feedbackValue2,
-      feedbackValue3,
-      feedbackValue4,
-      handleOk,
-      handleCancel
-    };
-  },
 });
 </script>
 <style scoped>
 .feedback-title {
-  color: rgba(102, 102, 102, 1);
-  font-size: 12px;
-  margin:0 0 8px 4px;
+    color: rgba(102, 102, 102, 1);
+    font-size: 12px;
+    margin: 0 0 8px 4px;
 }
 .feedback-content {
-  margin-bottom: 16px;
+    margin-bottom: 16px;
 }
-</style>
+</style>

+ 1 - 1
src/components/DocumentCards.vue

@@ -181,7 +181,7 @@ export default defineComponent({
         const showUpload = ref(false);
         const { helper } = inject("$global");
         const maxSize = 30 * 1024 * 1024;
-        const fileList = [];
+        let fileList = [];
         const showDeleteTooltip = ref(false);
         const deleteId = ref("");
         const selectFiles = (isSelect, type) => {

+ 17 - 128
src/views/Login.vue

@@ -5,53 +5,24 @@
                 <img src="@/assets/login.png" />
                 <p>欢迎使用</p>
             </header>
-            <p>手机号登录</p>
-            <p>获取验证码登录即注册成功</p>
+            <p>账号登录</p>
             <section>
+                <p>账号</p>
                 <div>
-                    <a-select
-                        :style="{ width: '80px', borderRight: '1px solid rgba(229, 229, 229, 1) !important' }"
-                        default-value="+86"
-                        :bordered="false"
-                    >
-                        <a-option>+86</a-option>
-                        <a-option>+81</a-option>
-                    </a-select>
-                    <a-input-number
-                        placeholder="请输入手机号"
-                        :style="{ width: '250px', height: '40px', background: 'transparent' }"
-                        v-model="phone"
-                    >
-                    </a-input-number>
+                    <a-input placeholder="请输入手机号" :style="{ width: '250px', height: '40px' }" v-model="username">
+                    </a-input>
                 </div>
             </section>
             <section>
+                <p>密码</p>
                 <div>
-                    <a-input-number
-                        placeholder="请输入验证码"
-                        :style="{
-                            width: '200px',
-                            height: '40px',
-                            background: 'transparent',
-                            border: '1px solid rgba(229, 229, 229, 1)'
-                        }"
-                        v-model="code"
-                    >
-                    </a-input-number>
-                    <p @click="send" v-if="!hasSend">发送验证码</p>
-                    <p v-else class="disabled">{{ count }}s</p>
+                    <a-input placeholder="请输入手机号" :style="{ width: '250px', height: '40px' }" v-model="password">
+                    </a-input>
                 </div>
             </section>
             <div @click="login">登录</div>
-            <span>登录即默认已阅读同意《模型服务协议》和《用户隐私协议》</span>
         </section>
-        <p>
-            © 2024 北京 XXXXX 科技有限公司 京ICP备2023011302号-3 | 京公网安备11010802043150号 | 用户协议 | 模型服务协议
-        </p>
     </main>
-    <!-- <a-modal v-model:visible="visible" :simple="true" :footer="false">
-    <mi-captcha ref="captcha" @success="sendSms" />
-  </a-modal> -->
 </template>
 <script>
 import { defineComponent, ref, inject } from "vue";
@@ -59,71 +30,16 @@ export default defineComponent({
     components: {},
     props: [],
     setup() {
-        const { ajax, helper } = inject("$global");
-        const phone = ref(NaN);
-        const code = ref(NaN);
-        const visible = ref(false);
-        const hasSend = ref(false);
-        const captcha = ref(null);
-        const count = ref(60);
-        let intervalId = null;
-        const sendSms = async () => {
-            // const result = await ajax.user.sendSms(phone.value);
-            // visible.value = false;
-            // if (result) {
-            helper.message("success", `已发送短信验证码`);
-            hasSend.value = true;
-            intervalId = setInterval(() => {
-                if (count.value > 0) {
-                    count.value--;
-                } else {
-                    clearInterval(intervalId);
-                    count.value = 60;
-                    hasSend.value = false;
-                }
-            }, 1000);
-            // }
-        };
-        const validatePhone = (phone) => {
-            const isValidate =
-                /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/.test(
-                    phone
-                );
-            return isValidate ? "" : "请输入正确的手机号";
-        };
-        const validateCode = (code) => {
-            const isValidate = /^\d{6}$/.test(code);
-            return isValidate ? "" : "请输入正确的验证码";
-        };
-        const send = () => {
-            const text = validatePhone(phone.value);
-            if (!text) {
-                // visible.value = true;
-                // captcha.value.reset(false);
-                sendSms();
-            } else {
-                helper.message("error", text);
-            }
-        };
+        const { ajax } = inject("$global");
+        const username = ref("poweruser123");
+        const password = ref("c++java123");
         const login = async () => {
-            helper.phone = phone.value;
-            helper.code = code.value;
-            if (helper.phone === 18811881188 && helper.code === 123123) {
-                helper.goLink("/");
-            } else {
-                helper.message("error", "登录失败");
-            }
+            ajax.user.login(username.value, password.value);
         };
         return {
             login,
-            visible,
-            count,
-            hasSend,
-            phone,
-            code,
-            send,
-            sendSms,
-            captcha
+            username,
+            password
         };
     }
 });
@@ -186,37 +102,10 @@ main {
             display: flex;
             justify-content: center;
             margin-top: 20px;
-            &:nth-child(4) {
-                > div {
-                    border: 1px solid rgba(229, 229, 229, 1);
-                    display: inline-flex;
-                }
-            }
-            &:nth-child(5) {
-                > div {
-                    display: flex;
-                    > p {
-                        width: 95px;
-                        height: 38px;
-                        line-height: 38px;
-                        background-color: rgba(255, 255, 255, 1);
-                        color: rgba(51, 51, 51, 1);
-                        font-size: 14px;
-                        border: 1px solid rgba(229, 229, 229, 1);
-                        text-align: center;
-                        margin-left: 40px;
-                        cursor: pointer;
-                        &:hover {
-                            opacity: 0.8;
-                        }
-                        &.disabled {
-                            cursor: not-allowed;
-                            &:hover {
-                                opacity: 1;
-                            }
-                        }
-                    }
-                }
+            > p {
+                display: flex;
+                align-items: center;
+                margin-right: 10px;
             }
         }
         > div {