Selaa lähdekoodia

fix:修复缺少动物房登录接口、需要登录,现在个人信息编辑报错,检查更换密码、头像等接口
服务号登录 输入 账号 不输入其他的 可以直接登录

张旭伟 1 viikko sitten
vanhempi
commit
4c5cb5cb14

+ 4 - 0
.env.development

@@ -23,6 +23,10 @@ VITE_INSTR_ADMIN = dashoo.labsop.apparatus-53000
 VITE_LEARNING = dashoo.labsop.learning-53000
 VITE_PLATFORM_API = dashoo.labsop.platform-53000
 VITE_LABORATORY: dashoo.labsop.laboratory-53000
+# 开启动物登录 1开启 0关闭
+VITE_ANIMAL_LOGIN = '1'
+VITE_ANIMAL_API_URL = https://192.168.0.133:5067/api/
+VITE_TENANT = default
 
 #公共配置
 VITE_UPLOAD = http://192.168.0.218:9933/weedfs/upload

+ 4 - 1
.env.production

@@ -12,6 +12,7 @@ ENV = production
 
 # 线上环境接口地址
 VITE_API_URL = /api/
+VITE_ANIMAL_API_URL = /api/
 VITE_API_WECHAT = /wechat/
 VITE_TENANT = default
 
@@ -24,7 +25,9 @@ VITE_INSTR_ADMIN = dashoo.labsop.apparatus-34000
 VITE_LEARNING = dashoo.labsop.learning-34000
 VITE_PLATFORM_API = dashoo.labsop.platform-34000
 VITE_LABORATORY: dashoo.labsop.laboratory-34000
-
+# 开启动物登录 1开启 0关闭
+VITE_ANIMAL_LOGIN = '1'
+VITE_TENANT = default
 
 #公共配置
 VITE_UPLOAD = /weedfs/upload

+ 2 - 7
components.d.ts

@@ -3,7 +3,7 @@
 // @ts-nocheck
 // Generated by unplugin-vue-components
 // Read more: https://github.com/vuejs/core/pull/3399
-export { }
+export {}
 
 declare module 'vue' {
   export interface GlobalComponents {
@@ -18,7 +18,6 @@ declare module 'vue' {
     VanCellGroup: typeof import('vant/es')['CellGroup']
     VanCheckbox: typeof import('vant/es')['Checkbox']
     VanCheckboxGroup: typeof import('vant/es')['CheckboxGroup']
-    VanDatePicker: typeof import('vant/es')['DatePicker']
     VanDialog: typeof import('vant/es')['Dialog']
     VanField: typeof import('vant/es')['Field']
     VanForm: typeof import('vant/es')['Form']
@@ -26,15 +25,10 @@ declare module 'vue' {
     VanImage: typeof import('vant/es')['Image']
     VanList: typeof import('vant/es')['List']
     VanNotify: typeof import('vant/es')['Notify']
-    VanPicker: typeof import('vant/es')['Picker']
-    VanPickerGroup: typeof import('vant/es')['PickerGroup']
-    VanPickerGroup: typeof import('vant/es')['PickerGroup']
     VanPopup: typeof import('vant/es')['Popup']
     VanRadio: typeof import('vant/es')['Radio']
     VanRadioGroup: typeof import('vant/es')['RadioGroup']
     VanRow: typeof import('vant/es')['Row']
-    VanStep: typeof import('vant/es')['Step']
-    VanSteps: typeof import('vant/es')['Steps']
     VanSwipe: typeof import('vant/es')['Swipe']
     VanSwipeItem: typeof import('vant/es')['SwipeItem']
     VanTab: typeof import('vant/es')['Tab']
@@ -43,5 +37,6 @@ declare module 'vue' {
     VanTabs: typeof import('vant/es')['Tabs']
     VanTag: typeof import('vant/es')['Tag']
     VanTextEllipsis: typeof import('vant/es')['TextEllipsis']
+    VanUploader: typeof import('vant/es')['Uploader']
   }
 }

+ 1 - 0
package.json

@@ -23,6 +23,7 @@
     "dayjs": "^1.11.13",
     "downloadjs": "^1.4.7",
     "element-plus": "^2.9.8",
+    "jsencrypt": "^3.5.4",
     "lodash": "^4.17.21",
     "mitt": "^3.0.1",
     "moment": "^2.29.4",

+ 41 - 0
src/stores/animalLogin.ts

@@ -0,0 +1,41 @@
+import { defineStore } from 'pinia';
+import JSEncrypt from 'jsencrypt'
+import axios from 'axios';
+const baseUrl = import.meta.env.VITE_ANIMAL_API_URL;
+
+let publicKey = '';
+let privateKey = '';
+
+// 动物房登录获取token
+export const useAnimalLogin = defineStore('animalLogin', () => {
+
+  async function getToken(username: string, password: string) {
+    await getPublicKey();
+    const encryptor = new JSEncrypt()
+    encryptor.setPublicKey(publicKey)
+    const encryptedPassword = encryptor.encrypt(password);
+    const res = await axios.post(baseUrl + 'lams/pc/login', { username, password: encryptedPassword, privateKey: privateKey });
+    console.log("动物房登录返回数据:", res.data);
+    if (res.data.code != 200) {
+      console.error(res.data.msg); // 修改这里
+      throw new Error(res.data.msg || '动物房登录失败');
+    }
+    if (res.status === 200 && res.data.code === 200){
+      localStorage.setItem('animalToken', res.data.token);
+    }
+  }
+
+  return {
+    getToken,
+  }
+});
+
+async function getPublicKey() {
+  const res = await axios.get(baseUrl + 'getPublicKey');
+  if (res.status === 200) {
+    publicKey = res.data.data.PublicKey;
+    privateKey = res.data.data.privateKey;
+  } else {
+    throw new Error('获取公钥失败');
+  }
+}

+ 24 - 4
src/view/login/index.vue

@@ -79,7 +79,8 @@ import { useUserInfo } from '/@/stores/userInfo'
 import { showDialog, showToast } from 'vant'
 import { HttpStatus } from '/@/constants/pageConstants'
 import { enhancedEncrypt, decryptLoginData, encryptWithBackendConfig } from '/@/utils/aesCrypto';
-
+import { useAnimalLogin } from '/@/stores/animalLogin';
+const animalLoginStore = useAnimalLogin();
 const router = useRouter()
 const route = useRoute()
 const sm3 = crypto.sm3
@@ -152,15 +153,34 @@ const getCaptchaImage = async () => {
 const onSignIn = async () => {
   state.loading.signIn = true
   const params = JSON.parse(JSON.stringify(state.form))
-  params.password = sm3(params.password)
   params.openId = openId.value
   params.unionId = unionId.value
+  // 是否开启动物房登录
+  const animalLogin = import.meta.env.VITE_ANIMAL_LOGIN;
+
+  if (animalLogin === '1') {
+    try {
+      await animalLoginStore.getToken(params.userName, state.form.password);
+    } catch (err: any) {
+      showToast(err.message || '动物房登录失败');
+      await getCaptchaImage();
+      state.loading.signIn = false;
+      return;
+    }
+  }
+  params.password = sm3(state.form.password)
   // params.password = (params.password)
   // sm3
   // 使用与后端完全匹配的加密函数加密密码
-  const encryptedPassword = encryptWithBackendConfig(params.password);
-  params.saltValue = encryptedPassword; // 后端AES IV常量
+  try {
+    const encryptedPassword = encryptWithBackendConfig(state.form.password);
+    params.saltValue = encryptedPassword; // 后端AES IV常量
+  } catch (e) {
+    // 不做处理
+  }
+
   const post = params.openId ? loginApi.weChatLogin : loginApi.signIn
+  // const post = loginApi.signIn
   const [err, res]: ToResponse = await to(post(params))
   state.loading.signIn = false
   if (err) {

+ 3 - 1
src/view/user/edit.vue

@@ -99,7 +99,8 @@ const state = reactive({
     email: '', // 电子邮件
     sex: '', // 性别
     avatar: '', // 头像图片地址
-    pgName: ''
+    pgName: '',
+    token: '',
   },
   dialog: {
     isShowDialog: false,
@@ -277,6 +278,7 @@ const onSubmit = async () => {
   }
   
   state.form.userId = state.form.id
+  state.form.token = localStorage.getItem('animalToken');
   const params = JSON.parse(JSON.stringify(state.form))
   const [err]: ToResponse = await to(userApi.updateProfile(params))
   if (err) return

+ 6 - 1
src/view/user/password.vue

@@ -52,6 +52,7 @@
   import axios from 'axios' 
   import crypto from 'sm-crypto';
   import { useLoginApi } from '/@/api/login'
+  import { enhancedEncrypt, decryptLoginData, encryptWithBackendConfig } from '/@/utils/aesCrypto';
   const sm3 = crypto.sm3;
   const router = useRouter()
   const storesUseUserInfo = useUserInfo()
@@ -68,7 +69,9 @@
     form: {
       oldPassword: '',
       newPassword: '',
-      newPassword2: ''
+      newPassword2: '',
+      saltValue: '',
+      token: ''
     },
     dialog: {
       isShowDialog: false,
@@ -107,7 +110,9 @@
     if (errValid) return
     const params = JSON.parse(JSON.stringify(state.form))
     params.oldPassword = sm3(params.oldPassword)
+    params.saltValue = encryptWithBackendConfig(params.newPassword)
     params.newPassword = sm3(params.newPassword)
+    params.token = localStorage.getItem('animalToken')
     const [err]: ToResponse = await to(userApi.changePassword(params))
     if (err) return
     showNotify({