|
@@ -6,64 +6,10 @@
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { onLaunch } from '@dcloudio/uni-app'
|
|
import { onLaunch } from '@dcloudio/uni-app'
|
|
|
-import { ref } from 'vue'
|
|
|
|
|
-import { login } from './api/auth.js'
|
|
|
|
|
-import { storage, showToast } from './utils/index.js'
|
|
|
|
|
-import JSEncrypt from 'jsencrypt'
|
|
|
|
|
-
|
|
|
|
|
-// 默认登录账号
|
|
|
|
|
-const DEFAULT_ACCOUNT = {
|
|
|
|
|
- mobilePhone: '13018061579',
|
|
|
|
|
- password: 'adb123'
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// RSA加密函数
|
|
|
|
|
-const encryptData = (str) => {
|
|
|
|
|
- let encryptor = new JSEncrypt()
|
|
|
|
|
- // 设置公钥(从后端配置文件获取)
|
|
|
|
|
- let publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNc4Zrvk3E0mUkO8NOeNYOOaPI4uLoBAuDt9Rp0urX7y0wq7vvQzytvwzXXeM9Xp89j7g4ZLR7qBLBCj3QNPH0SUjE1yy9KVBKdjkPre7WT+plS74s2rJz/hygKiJ3Vxa+Z15v6JEHy/3/+i9gW3p/bCLaMQtvGemNvDXwCTwINQIDAQAB'
|
|
|
|
|
- encryptor.setPublicKey(publicKey)
|
|
|
|
|
- // 加密数据
|
|
|
|
|
- return encryptor.encrypt(str)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 自动登录函数
|
|
|
|
|
-const autoLogin = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- // 检查是否已登录
|
|
|
|
|
- const token = storage.get('token')
|
|
|
|
|
- if (token) {
|
|
|
|
|
- console.log('已登录,跳过自动登录')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- console.log('执行自动登录...')
|
|
|
|
|
- // 加密密码
|
|
|
|
|
- const encryptedPassword = encryptData(DEFAULT_ACCOUNT.password)
|
|
|
|
|
- const res = await login(DEFAULT_ACCOUNT.mobilePhone, encryptedPassword)
|
|
|
|
|
-
|
|
|
|
|
- if (res && res.code === 200) {
|
|
|
|
|
- // 保存token到缓存
|
|
|
|
|
- storage.set('token', res.data.accessToken)
|
|
|
|
|
- // 保存用户信息
|
|
|
|
|
- storage.set('userInfo', res.data)
|
|
|
|
|
-
|
|
|
|
|
- console.log('自动登录成功')
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('自动登录失败:', res?.msg || '未知错误')
|
|
|
|
|
- showToast('自动登录失败,请手动登录', 'error')
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('自动登录异常:', error)
|
|
|
|
|
- showToast('自动登录异常,请手动登录', 'error')
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
// 应用启动时执行
|
|
// 应用启动时执行
|
|
|
onLaunch(() => {
|
|
onLaunch(() => {
|
|
|
console.log('App launched')
|
|
console.log('App launched')
|
|
|
- // 执行自动登录
|
|
|
|
|
- autoLogin()
|
|
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|