flat: 微调
This commit is contained in:
12
App.vue
12
App.vue
@@ -6,6 +6,7 @@ import usePageAnimation from './hook/usePageAnimation';
|
||||
import useDictStore from './stores/useDictStore';
|
||||
const { $api, navTo, appendScriptTagElement, aes_Decrypt, sm2_Decrypt, safeReLaunch } = inject('globalFunction');
|
||||
import config from '@/config.js';
|
||||
import baseDB from '@/utils/db.js';
|
||||
usePageAnimation();
|
||||
const appword = 'aKd20dbGdFvmuwrt'; // 固定值
|
||||
|
||||
@@ -15,10 +16,12 @@ onLaunch((options) => {
|
||||
console.warn('爱山东环境');
|
||||
getUserInfo();
|
||||
useUserStore().changMiniProgramAppStatus(false);
|
||||
useUserStore().changMachineEnv(false);
|
||||
return;
|
||||
}
|
||||
if (window.hh) {
|
||||
if (isY9MachineType()) {
|
||||
console.warn('求职一体机环境');
|
||||
baseDB.resetAndReinit(); // 清空indexdb
|
||||
useUserStore().logOutApp();
|
||||
useUserStore().changMiniProgramAppStatus(true);
|
||||
useUserStore().changMachineEnv(true);
|
||||
@@ -27,6 +30,7 @@ onLaunch((options) => {
|
||||
// 正式上线去除此方法
|
||||
console.warn('浏览器环境');
|
||||
useUserStore().changMiniProgramAppStatus(true);
|
||||
useUserStore().changMachineEnv(false);
|
||||
useUserStore().initSeesionId(); //更新
|
||||
let token = uni.getStorageSync('token') || '';
|
||||
if (token) {
|
||||
@@ -50,6 +54,12 @@ onHide(() => {
|
||||
console.log('App Hide');
|
||||
});
|
||||
|
||||
function isY9MachineType() {
|
||||
const ua = navigator.userAgent;
|
||||
const isY9Machine = /Y9-ZYYH/i.test(ua); // 匹配机器型号
|
||||
return isY9Machine;
|
||||
}
|
||||
|
||||
function getUserInfo() {
|
||||
lightAppJssdk.user.getUserInfoWithEncryptedParamByAppId({
|
||||
appId: config.appInfo.loveShandong, // 接入方在成功创建应用后自动生成
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default {
|
||||
// baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网
|
||||
baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试
|
||||
baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网
|
||||
// baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试
|
||||
// baseUrl: 'http://192.168.3.29:8081',
|
||||
// baseUrl: 'http://10.213.6.207:19010/api',
|
||||
// 语音转文字
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
eruda.init();
|
||||
</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>
|
||||
// VConsole 默认会挂载到 `window.VConsole` 上
|
||||
var vConsole = new window.VConsole();
|
||||
</script> -->
|
||||
</script>
|
||||
<!-- 爱山东jssdk 本sdk存在性能问题 -->
|
||||
<script type="text/javascript" src="./static/js/jsbridge.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
@@ -355,4 +355,4 @@ const handleItemClick = (item) => {
|
||||
border-radius: 2rpx
|
||||
background: #A2A2A2;
|
||||
transform: rotate(45deg)
|
||||
</style>
|
||||
</style>
|
||||
@@ -14,26 +14,47 @@ const useLocationStore = defineStore("location", () => {
|
||||
const longitudeVal = ref(null) // 经度
|
||||
const latitudeVal = ref(null) //纬度
|
||||
|
||||
function getLocation() {
|
||||
function getLocation() { // 获取经纬度两个平台
|
||||
return new Promise((resole, reject) => {
|
||||
try {
|
||||
lightAppJssdk.map.getLocation({
|
||||
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('用户位置获取失败')
|
||||
console.log('失败', data)
|
||||
}
|
||||
})
|
||||
if (lightAppJssdk.map) {
|
||||
lightAppJssdk.map.getLocation({
|
||||
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('用户位置获取失败')
|
||||
}
|
||||
})
|
||||
} 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) {
|
||||
longitudeVal.value = 120.382665
|
||||
latitudeVal.value = 36.066938
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
msg,
|
||||
$api,
|
||||
} from '../common/globalFunction';
|
||||
import baseDB from '@/utils/db.js';
|
||||
|
||||
// 简历完成度计算
|
||||
function getResumeCompletionPercentage(resume) {
|
||||
@@ -125,7 +126,9 @@ const useUserStore = defineStore("user", () => {
|
||||
// 获取消息列表
|
||||
useReadMsg().fetchMessages()
|
||||
// 获取用户信息
|
||||
return getUserResume()
|
||||
const resume = await getUserResume()
|
||||
await baseDB.init(); // 登录成功初始化
|
||||
return resume
|
||||
}
|
||||
|
||||
const setUserInfo = (values) => {
|
||||
|
||||
@@ -34,11 +34,12 @@ const useChatGroupDBStore = defineStore("messageGroup", () => {
|
||||
const chatSessionID = ref('')
|
||||
const lastDateRef = ref('')
|
||||
|
||||
async function init() {
|
||||
async function init() { // 初始化数据,有则用,无则更新
|
||||
// 获取所有数据
|
||||
setTimeout(async () => {
|
||||
if (!baseDB.isDBReady) await baseDB.initDB();
|
||||
const result = await baseDB.db.getAll(tableName.value);
|
||||
console.log('result', result)
|
||||
// 1、判断是否有数据,没数据请求服务器
|
||||
if (result.length) {
|
||||
console.warn('本地数据库存在数据')
|
||||
|
||||
105
utils/db.js
105
utils/db.js
@@ -1,24 +1,50 @@
|
||||
// BaseDBStore.js
|
||||
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
|
||||
// import UniStorageHelper from '../common/UniStorageHelper'
|
||||
import useChatGroupDBStore from '@/stores/userChatGroupStore'
|
||||
import config from '@/config'
|
||||
|
||||
class BaseStore {
|
||||
db = null
|
||||
isDBReady = false
|
||||
dbName = 'BrowsingHistory' // 'AppMainDB'
|
||||
dbName = 'AppMainDB'
|
||||
initPromise = null
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -28,30 +54,28 @@ class BaseStore {
|
||||
}
|
||||
const localVersion = uni.getStorageSync('indexedDBVersion') || 1
|
||||
console.log('DBVersion: ', localVersion, config.DBversion)
|
||||
if (localVersion === config.DBversion) {
|
||||
return this.initDB() // 🟢 记得加 return
|
||||
|
||||
if (Number(localVersion) === Number(config.DBversion)) {
|
||||
return this.initDB()
|
||||
} else {
|
||||
console.log('清空本地数据库')
|
||||
await this.clearDB() // 🟢 建议用 await
|
||||
console.log('检测到版本更新,清空重置旧数据库')
|
||||
await this.clearDB()
|
||||
uni.setStorageSync('indexedDBVersion', config.DBversion);
|
||||
return this.initDB(); // 🟢 记得加 return
|
||||
return this.initDB();
|
||||
}
|
||||
}
|
||||
|
||||
initDB() {
|
||||
// // #ifdef H5
|
||||
this.db = new IndexedDBHelper(this.dbName, config.DBversion);
|
||||
// // #endif
|
||||
|
||||
return this.db.openDB([{
|
||||
name: 'record',
|
||||
keyPath: "id",
|
||||
autoIncrement: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
{
|
||||
name: 'messageGroup',
|
||||
keyPath: "id",
|
||||
autoIncrement: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
{
|
||||
name: 'messages',
|
||||
@@ -65,12 +89,12 @@ class BaseStore {
|
||||
},
|
||||
{
|
||||
name: 'api_cache',
|
||||
keyPath: "cacheKey", // 使用 URL+参数 作为主键
|
||||
keyPath: "cacheKey",
|
||||
indexes: []
|
||||
}
|
||||
]).then(async () => {
|
||||
// 这里原来的逻辑保留
|
||||
if (useChatGroupDBStore) {
|
||||
// 确保 Pinia Store 已准备好后再初始化子项
|
||||
useChatGroupDBStore().init()
|
||||
}
|
||||
this.isDBReady = true
|
||||
@@ -79,13 +103,44 @@ class BaseStore {
|
||||
}
|
||||
|
||||
async clearDB() {
|
||||
return new Promise((resolve, rejetc) => {
|
||||
new IndexedDBHelper().deleteDB(this.dbName).then(() => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
// 修正拼写错误并优化 Promise 写法
|
||||
return new IndexedDBHelper().deleteDB(this.dbName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 彻底清空数据库并重新初始化
|
||||
* 适用于切换账号或手动清理缓存
|
||||
* 非特殊情况不要重置!!!!!!!!!!!!!!!
|
||||
*/
|
||||
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()
|
||||
export default baseDB
|
||||
Reference in New Issue
Block a user