flat: 微调

This commit is contained in:
Apcallover
2025-12-16 20:24:03 +08:00
parent 4a03b4d4cb
commit 80213b18e9
9 changed files with 729 additions and 617 deletions

12
App.vue
View File

@@ -6,6 +6,7 @@ import usePageAnimation from './hook/usePageAnimation';
import useDictStore from './stores/useDictStore'; import useDictStore from './stores/useDictStore';
const { $api, navTo, appendScriptTagElement, aes_Decrypt, sm2_Decrypt, safeReLaunch } = inject('globalFunction'); const { $api, navTo, appendScriptTagElement, aes_Decrypt, sm2_Decrypt, safeReLaunch } = inject('globalFunction');
import config from '@/config.js'; import config from '@/config.js';
import baseDB from '@/utils/db.js';
usePageAnimation(); usePageAnimation();
const appword = 'aKd20dbGdFvmuwrt'; // 固定值 const appword = 'aKd20dbGdFvmuwrt'; // 固定值
@@ -15,10 +16,12 @@ onLaunch((options) => {
console.warn('爱山东环境'); console.warn('爱山东环境');
getUserInfo(); getUserInfo();
useUserStore().changMiniProgramAppStatus(false); useUserStore().changMiniProgramAppStatus(false);
useUserStore().changMachineEnv(false);
return; return;
} }
if (window.hh) { if (isY9MachineType()) {
console.warn('求职一体机环境'); console.warn('求职一体机环境');
baseDB.resetAndReinit(); // 清空indexdb
useUserStore().logOutApp(); useUserStore().logOutApp();
useUserStore().changMiniProgramAppStatus(true); useUserStore().changMiniProgramAppStatus(true);
useUserStore().changMachineEnv(true); useUserStore().changMachineEnv(true);
@@ -27,6 +30,7 @@ onLaunch((options) => {
// 正式上线去除此方法 // 正式上线去除此方法
console.warn('浏览器环境'); console.warn('浏览器环境');
useUserStore().changMiniProgramAppStatus(true); useUserStore().changMiniProgramAppStatus(true);
useUserStore().changMachineEnv(false);
useUserStore().initSeesionId(); //更新 useUserStore().initSeesionId(); //更新
let token = uni.getStorageSync('token') || ''; let token = uni.getStorageSync('token') || '';
if (token) { if (token) {
@@ -50,6 +54,12 @@ onHide(() => {
console.log('App Hide'); console.log('App Hide');
}); });
function isY9MachineType() {
const ua = navigator.userAgent;
const isY9Machine = /Y9-ZYYH/i.test(ua); // 匹配机器型号
return isY9Machine;
}
function getUserInfo() { function getUserInfo() {
lightAppJssdk.user.getUserInfoWithEncryptedParamByAppId({ lightAppJssdk.user.getUserInfoWithEncryptedParamByAppId({
appId: config.appInfo.loveShandong, // 接入方在成功创建应用后自动生成 appId: config.appInfo.loveShandong, // 接入方在成功创建应用后自动生成

View File

@@ -1,6 +1,6 @@
export default { export default {
// baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网 baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网
baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试 // baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试
// baseUrl: 'http://192.168.3.29:8081', // baseUrl: 'http://192.168.3.29:8081',
// baseUrl: 'http://10.213.6.207:19010/api', // baseUrl: 'http://10.213.6.207:19010/api',
// 语音转文字 // 语音转文字

View File

@@ -23,11 +23,11 @@
eruda.init(); eruda.init();
</script> --> </script> -->
<!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script> <script>
// VConsole 默认会挂载到 `window.VConsole` 上 // VConsole 默认会挂载到 `window.VConsole` 上
var vConsole = new window.VConsole(); var vConsole = new window.VConsole();
</script> --> </script>
<!-- 爱山东jssdk 本sdk存在性能问题 --> <!-- 爱山东jssdk 本sdk存在性能问题 -->
<script type="text/javascript" src="./static/js/jsbridge.js"></script> <script type="text/javascript" src="./static/js/jsbridge.js"></script>
<!-- <script type="text/javascript" src="./static/js/jweixin-1.4.0.js"></script> --> <!-- <script type="text/javascript" src="./static/js/jweixin-1.4.0.js"></script> -->

File diff suppressed because it is too large Load Diff

View File

@@ -355,4 +355,4 @@ const handleItemClick = (item) => {
border-radius: 2rpx border-radius: 2rpx
background: #A2A2A2; background: #A2A2A2;
transform: rotate(45deg) transform: rotate(45deg)
</style> </style>

View File

@@ -14,26 +14,47 @@ const useLocationStore = defineStore("location", () => {
const longitudeVal = ref(null) // 经度 const longitudeVal = ref(null) // 经度
const latitudeVal = ref(null) //纬度 const latitudeVal = ref(null) //纬度
function getLocation() { function getLocation() { // 获取经纬度两个平台
return new Promise((resole, reject) => { return new Promise((resole, reject) => {
try { try {
lightAppJssdk.map.getLocation({ if (lightAppJssdk.map) {
success: function(data) { lightAppJssdk.map.getLocation({
longitudeVal.value = Number(data.longitude) success: function(data) {
latitudeVal.value = Number(data.latitude) longitudeVal.value = Number(data.longitude)
resole(data) latitudeVal.value = Number(data.latitude)
}, resole(data)
fail: function(data) { },
longitudeVal.value = 120.382665 fail: function(data) {
latitudeVal.value = 36.066938 longitudeVal.value = 120.382665
resole({ latitudeVal.value = 36.066938
longitude: 120.382665, resole({
latitude: 36.066938 longitude: 120.382665,
}) latitude: 36.066938
msg('用户位置获取失败') })
console.log('失败', data) msg('用户位置获取失败')
} }
}) })
} else {
uni.getLocation({
type: 'gcj02',
highAccuracyExpireTime: 3000,
isHighAccuracy: true,
success: function(data) {
longitudeVal.value = Number(data.longitude)
latitudeVal.value = Number(data.latitude)
resole(data)
},
fail: function(data) {
longitudeVal.value = 120.382665
latitudeVal.value = 36.066938
resole({
longitude: 120.382665,
latitude: 36.066938
})
msg('用户位置获取失败')
}
});
}
} catch (e) { } catch (e) {
longitudeVal.value = 120.382665 longitudeVal.value = 120.382665
latitudeVal.value = 36.066938 latitudeVal.value = 36.066938

View File

@@ -18,6 +18,7 @@ import {
msg, msg,
$api, $api,
} from '../common/globalFunction'; } from '../common/globalFunction';
import baseDB from '@/utils/db.js';
// 简历完成度计算 // 简历完成度计算
function getResumeCompletionPercentage(resume) { function getResumeCompletionPercentage(resume) {
@@ -125,7 +126,9 @@ const useUserStore = defineStore("user", () => {
// 获取消息列表 // 获取消息列表
useReadMsg().fetchMessages() useReadMsg().fetchMessages()
// 获取用户信息 // 获取用户信息
return getUserResume() const resume = await getUserResume()
await baseDB.init(); // 登录成功初始化
return resume
} }
const setUserInfo = (values) => { const setUserInfo = (values) => {

View File

@@ -34,11 +34,12 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
const chatSessionID = ref('') const chatSessionID = ref('')
const lastDateRef = ref('') const lastDateRef = ref('')
async function init() { async function init() { // 初始化数据,有则用,无则更新
// 获取所有数据 // 获取所有数据
setTimeout(async () => { setTimeout(async () => {
if (!baseDB.isDBReady) await baseDB.initDB(); if (!baseDB.isDBReady) await baseDB.initDB();
const result = await baseDB.db.getAll(tableName.value); const result = await baseDB.db.getAll(tableName.value);
console.log('result', result)
// 1、判断是否有数据没数据请求服务器 // 1、判断是否有数据没数据请求服务器
if (result.length) { if (result.length) {
console.warn('本地数据库存在数据') console.warn('本地数据库存在数据')

View File

@@ -1,24 +1,50 @@
// BaseDBStore.js
import IndexedDBHelper from '@/common/IndexedDBHelper.js' import IndexedDBHelper from '@/common/IndexedDBHelper.js'
// import UniStorageHelper from '../common/UniStorageHelper'
import useChatGroupDBStore from '@/stores/userChatGroupStore' import useChatGroupDBStore from '@/stores/userChatGroupStore'
import config from '@/config' import config from '@/config'
class BaseStore { class BaseStore {
db = null db = null
isDBReady = false isDBReady = false
dbName = 'BrowsingHistory' // 'AppMainDB' dbName = 'AppMainDB'
initPromise = null initPromise = null
constructor() { constructor() {
this.initPromise = this.checkAndInitDB() // 不再自动执行初始化
} }
async getDB() { /**
if (!this.initPromise) { * 手动初始化入口、建立连接、如果版本号不对付才会清理
this.initPromise = this.checkAndInitDB(); * 建议在登录成功后调用await baseDB.init()
*/
async init() {
// 如果已经有初始化任务在进行了,直接返回该任务
if (this.initPromise) {
return this.initPromise;
}
// 创建初始化任务
this.initPromise = this.checkAndInitDB();
try {
await this.initPromise;
console.log('数据库初始化成功');
} catch (error) {
this.initPromise = null; // 初始化失败允许下次重试
console.error('数据库初始化失败:', error);
throw error;
}
return this.db;
}
/**
* 获取数据库实例
* 如果没初始化,会强制触发一次 init
*/
async getDB() {
if (!this.isDBReady) {
return await this.init();
} }
await this.initPromise; // 等待初始化完成
return this.db; return this.db;
} }
@@ -28,30 +54,28 @@ class BaseStore {
} }
const localVersion = uni.getStorageSync('indexedDBVersion') || 1 const localVersion = uni.getStorageSync('indexedDBVersion') || 1
console.log('DBVersion: ', localVersion, config.DBversion) console.log('DBVersion: ', localVersion, config.DBversion)
if (localVersion === config.DBversion) {
return this.initDB() // 🟢 记得加 return if (Number(localVersion) === Number(config.DBversion)) {
return this.initDB()
} else { } else {
console.log('清空本地数据库') console.log('检测到版本更新,清空重置旧数据库')
await this.clearDB() // 🟢 建议用 await await this.clearDB()
uni.setStorageSync('indexedDBVersion', config.DBversion); uni.setStorageSync('indexedDBVersion', config.DBversion);
return this.initDB(); // 🟢 记得加 return return this.initDB();
} }
} }
initDB() { initDB() {
// // #ifdef H5
this.db = new IndexedDBHelper(this.dbName, config.DBversion); this.db = new IndexedDBHelper(this.dbName, config.DBversion);
// // #endif
return this.db.openDB([{ return this.db.openDB([{
name: 'record', name: 'record',
keyPath: "id", keyPath: "id",
autoIncrement: true, autoIncrement: true
}, },
{ {
name: 'messageGroup', name: 'messageGroup',
keyPath: "id", keyPath: "id",
autoIncrement: true, autoIncrement: true
}, },
{ {
name: 'messages', name: 'messages',
@@ -65,12 +89,12 @@ class BaseStore {
}, },
{ {
name: 'api_cache', name: 'api_cache',
keyPath: "cacheKey", // 使用 URL+参数 作为主键 keyPath: "cacheKey",
indexes: [] indexes: []
} }
]).then(async () => { ]).then(async () => {
// 这里原来的逻辑保留
if (useChatGroupDBStore) { if (useChatGroupDBStore) {
// 确保 Pinia Store 已准备好后再初始化子项
useChatGroupDBStore().init() useChatGroupDBStore().init()
} }
this.isDBReady = true this.isDBReady = true
@@ -79,13 +103,44 @@ class BaseStore {
} }
async clearDB() { async clearDB() {
return new Promise((resolve, rejetc) => { // 修正拼写错误并优化 Promise 写法
new IndexedDBHelper().deleteDB(this.dbName).then(() => { return new IndexedDBHelper().deleteDB(this.dbName);
resolve() }
})
}) /**
* 彻底清空数据库并重新初始化
* 适用于切换账号或手动清理缓存
* 非特殊情况不要重置!!!!!!!!!!!!!!!
*/
async resetAndReinit() {
console.warn('开始执行数据库重置...');
if (this.db && this.db.db) {
this.db.db.close();
}
try {
await this.clearDB();
// 3. 重置内部状态
this.db = null;
this.isDBReady = false;
this.initPromise = null;
uni.setStorageSync('indexedDBVersion', config.DBversion);
// 5. 重新调用初始化流程
await this.init();
console.log('数据库重置及初始化完成');
return true;
} catch (error) {
console.error('数据库重置失败:', error);
throw error;
}
} }
} }
// 导出实例
const baseDB = new BaseStore() const baseDB = new BaseStore()
export default baseDB export default baseDB