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> -->
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
<view class="qrcode-border">
|
||||
<view class="qrcode-content">
|
||||
<view class="qrcode-pattern">
|
||||
<image class="qrcode-img" src="@/static/icon/qrcode-example.png" mode="scaleToFill" />
|
||||
<image
|
||||
class="qrcode-img"
|
||||
src="@/static/icon/qrcode-example.png"
|
||||
mode="scaleToFill"
|
||||
/>
|
||||
<view class="qrcode-corner top-left"></view>
|
||||
<view class="qrcode-corner top-right"></view>
|
||||
<view class="qrcode-corner bottom-left"></view>
|
||||
@@ -34,7 +38,10 @@
|
||||
</view>
|
||||
<!-- 刷新提示 -->
|
||||
<view class="refresh-tips" v-if="countdown > 0">
|
||||
<view class="countdown-text"><span class="countdown-num">{{ countdown }}</span> 秒后二维码过期</view>
|
||||
<view class="countdown-text">
|
||||
<span class="countdown-num">{{ countdown }}</span>
|
||||
秒后二维码过期
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 扫码成功提示 -->
|
||||
@@ -122,7 +129,12 @@
|
||||
</view>
|
||||
<view class="content-input" @click="changeArea">
|
||||
<view class="input-titile">求职区域</view>
|
||||
<input class="input-con" v-model="state.areaText" disabled placeholder="请选择您的求职区域" />
|
||||
<input
|
||||
class="input-con"
|
||||
v-model="state.areaText"
|
||||
disabled
|
||||
placeholder="请选择您的求职区域"
|
||||
/>
|
||||
</view>
|
||||
<view class="content-input" @click="changeJobs">
|
||||
<view class="input-titile">求职岗位</view>
|
||||
@@ -138,7 +150,12 @@
|
||||
</view>
|
||||
<view class="content-input" @click="changeSalay">
|
||||
<view class="input-titile">期望薪资</view>
|
||||
<input class="input-con" v-model="state.salayText" disabled placeholder="请选择您的期望薪资" />
|
||||
<input
|
||||
class="input-con"
|
||||
v-model="state.salayText"
|
||||
disabled
|
||||
placeholder="请选择您的期望薪资"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="next-btn" @tap="complete">开启求职之旅</view>
|
||||
@@ -202,7 +219,7 @@ const showSuccessTip = ref(false);
|
||||
|
||||
onLoad((parmas) => {
|
||||
getTreeselect();
|
||||
if(!isMachineEnv.value) $api.msg('请完善微简历');
|
||||
if (!isMachineEnv.value) $api.msg('请完善微简历');
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
@@ -238,7 +255,7 @@ const resetCountdown = () => {
|
||||
} else {
|
||||
qrcodeExpired.value = true;
|
||||
clearInterval(countdownTimer);
|
||||
stopScanAnimation()
|
||||
stopScanAnimation();
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
@@ -348,6 +365,11 @@ function getTreeselect() {
|
||||
}
|
||||
|
||||
function loginbackdoor() {
|
||||
if (isMachineEnv.value) {
|
||||
useUserStore().logOutApp();
|
||||
$api.msg('返回首页');
|
||||
return;
|
||||
}
|
||||
$api.createRequest('/app/mock/login', {}, 'post').then((resData) => {
|
||||
$api.msg('模拟帐号密码测试登录成功');
|
||||
loginSetToken(resData.token).then((resume) => {
|
||||
@@ -478,9 +500,9 @@ function complete() {
|
||||
background-color: #fff;
|
||||
position: relative;
|
||||
}
|
||||
.qrcode-img{
|
||||
.qrcode-img {
|
||||
width: 100%;
|
||||
height:100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.qrcode-corner {
|
||||
@@ -583,7 +605,7 @@ function complete() {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.countdown-num{
|
||||
.countdown-num {
|
||||
margin-right: 5rpx;
|
||||
color: #1677ff;
|
||||
font-size: 30rpx;
|
||||
|
||||
@@ -14,9 +14,10 @@ const useLocationStore = defineStore("location", () => {
|
||||
const longitudeVal = ref(null) // 经度
|
||||
const latitudeVal = ref(null) //纬度
|
||||
|
||||
function getLocation() {
|
||||
function getLocation() { // 获取经纬度两个平台
|
||||
return new Promise((resole, reject) => {
|
||||
try {
|
||||
if (lightAppJssdk.map) {
|
||||
lightAppJssdk.map.getLocation({
|
||||
success: function(data) {
|
||||
longitudeVal.value = Number(data.longitude)
|
||||
@@ -31,9 +32,29 @@ const useLocationStore = defineStore("location", () => {
|
||||
latitude: 36.066938
|
||||
})
|
||||
msg('用户位置获取失败')
|
||||
console.log('失败', data)
|
||||
}
|
||||
})
|
||||
} 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