flat: 性能优化,招聘会时间筛选性能优化、精选企业性能优化,封装缓存request、indexDb方法,主要用于不常更新的接口,以达到毫秒级性能
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import '@/lib/encryption/sm4.min.js'
|
import '@/lib/encryption/sm4.min.js'
|
||||||
import useUserStore from "../stores/useUserStore";
|
import useUserStore from "../stores/useUserStore";
|
||||||
import {
|
import {
|
||||||
|
createRequestWithCache,
|
||||||
createRequest,
|
createRequest,
|
||||||
uploadFile
|
uploadFile
|
||||||
} from "../utils/request";
|
} from "../utils/request";
|
||||||
@@ -624,6 +625,7 @@ export const $api = {
|
|||||||
sendingMiniProgramMessage,
|
sendingMiniProgramMessage,
|
||||||
copyText,
|
copyText,
|
||||||
aes_Decrypt,
|
aes_Decrypt,
|
||||||
|
createRequestWithCache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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',
|
||||||
// 语音转文字
|
// 语音转文字
|
||||||
|
|||||||
@@ -50,10 +50,11 @@ function delCollectionCard(item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPremiumList() {
|
function getPremiumList() {
|
||||||
$api.createRequest('/app/company/card').then((resData) => {
|
const LoadCache = (resData) => {
|
||||||
const { rows, total } = resData;
|
const { rows, total } = resData;
|
||||||
list.value = rows;
|
list.value = rows;
|
||||||
});
|
};
|
||||||
|
$api.createRequestWithCache('/app/company/card', {}, 'GET', false, {}, LoadCache).then(LoadCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
function seeDetail(item) {
|
function seeDetail(item) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<view
|
<view
|
||||||
class="item button-click"
|
class="item button-click"
|
||||||
:class="{
|
:class="{
|
||||||
optional:hasZphInData(item),
|
optional: item.isThisMonth && hasZphInData(item),
|
||||||
noOptional: !item.isThisMonth,
|
noOptional: !item.isThisMonth,
|
||||||
active: current.date === item.date && item.isThisMonth,
|
active: current.date === item.date && item.isThisMonth,
|
||||||
}"
|
}"
|
||||||
@@ -60,10 +60,9 @@ const pages = reactive({
|
|||||||
month: 0,
|
month: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasZphDateArray = ref([])
|
const hasZphDateArray = ref([]);
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
updateDateArray()
|
|
||||||
if (options.date) {
|
if (options.date) {
|
||||||
current.value = {
|
current.value = {
|
||||||
date: options?.date || null,
|
date: options?.date || null,
|
||||||
@@ -81,20 +80,30 @@ onLoad((options) => {
|
|||||||
addMonth();
|
addMonth();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (options.entrance === 'careerfair') {
|
||||||
|
updateDateArray();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function hasZphInData(item) {
|
function hasZphInData(item) {
|
||||||
return hasZphDateArray.value.some(date=>date == item.date)
|
if (!item || typeof item.date !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateArray = Array.isArray(hasZphDateArray.value) ? hasZphDateArray.value : [];
|
||||||
|
|
||||||
|
return dateArray.some((date) => {
|
||||||
|
return typeof date === 'string' && date === item.date;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateDateArray() {
|
async function updateDateArray() {
|
||||||
if(localStorage.getItem('hasZphDateArray')) hasZphDateArray.value = localStorage.getItem('hasZphDateArray')
|
const LoadCache = (resData) => {
|
||||||
|
if (resData.code === 200) {
|
||||||
let res = await $api.createRequest('/app/internal/getDateList', {}, 'get')
|
hasZphDateArray.value = resData.data;
|
||||||
if(res.data){
|
|
||||||
hasZphDateArray.value = res.data
|
|
||||||
localStorage.setItem('hasZphDateArray',res.data)
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
$api.createRequestWithCache('/app/internal/getDateList', {}, 'GET', false, {}, LoadCache).then(LoadCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
function backParams() {
|
function backParams() {
|
||||||
|
|||||||
@@ -13,7 +13,14 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="header-input btn-feel">
|
<view class="header-input btn-feel">
|
||||||
<uni-icons class="iconsearch" color="#666666" type="search" size="18"></uni-icons>
|
<uni-icons class="iconsearch" color="#666666" type="search" size="18"></uni-icons>
|
||||||
<input v-model="pageState.zphmc" confirm-type="search" @confirm="getFair" class="input" placeholder="招聘会" placeholder-class="inputplace" />
|
<input
|
||||||
|
v-model="pageState.zphmc"
|
||||||
|
confirm-type="search"
|
||||||
|
@confirm="getFair"
|
||||||
|
class="input"
|
||||||
|
placeholder="招聘会"
|
||||||
|
placeholder-class="inputplace"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
<view class="header-date">
|
<view class="header-date">
|
||||||
<view class="data-week">
|
<view class="data-week">
|
||||||
@@ -42,7 +49,14 @@
|
|||||||
class="card press-button"
|
class="card press-button"
|
||||||
v-for="(item, index) in fairList"
|
v-for="(item, index) in fairList"
|
||||||
:key="index"
|
:key="index"
|
||||||
@click="navTo('/packageA/pages/exhibitors/exhibitors?jobFairId=' + item.zphID + '&jobFairName=' + item.zphmc)"
|
@click="
|
||||||
|
navTo(
|
||||||
|
'/packageA/pages/exhibitors/exhibitors?jobFairId=' +
|
||||||
|
item.zphID +
|
||||||
|
'&jobFairName=' +
|
||||||
|
item.zphmc
|
||||||
|
)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<view class="card-title">{{ item.zphmc }}</view>
|
<view class="card-title">{{ item.zphmc }}</view>
|
||||||
<view class="card-row">
|
<view class="card-row">
|
||||||
@@ -95,7 +109,7 @@ import Tabbar from '@/components/tabbar/midell-box.vue';
|
|||||||
import useLocationStore from '@/stores/useLocationStore';
|
import useLocationStore from '@/stores/useLocationStore';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
const { longitudeVal, latitudeVal } = storeToRefs(useLocationStore());
|
const { longitudeVal, latitudeVal } = storeToRefs(useLocationStore());
|
||||||
const { $api, navTo, cloneDeep,debounce } = inject('globalFunction');
|
const { $api, navTo, cloneDeep, debounce } = inject('globalFunction');
|
||||||
const weekList = ref([]);
|
const weekList = ref([]);
|
||||||
const fairList = ref([]);
|
const fairList = ref([]);
|
||||||
const currentDay = ref({});
|
const currentDay = ref({});
|
||||||
@@ -108,7 +122,7 @@ const pageState = reactive({
|
|||||||
total: 0,
|
total: 0,
|
||||||
maxPage: 2,
|
maxPage: 2,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
zphmc:''
|
zphmc: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
@@ -122,7 +136,7 @@ onLoad(() => {
|
|||||||
startDate: currentDate,
|
startDate: currentDate,
|
||||||
});
|
});
|
||||||
weekList.value = result;
|
weekList.value = result;
|
||||||
currentDay.value.fullDate = result[0].fullDate
|
currentDay.value.fullDate = result[0].fullDate;
|
||||||
getFair('refresh');
|
getFair('refresh');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,6 +144,7 @@ function toSelectDate() {
|
|||||||
navTo('/packageA/pages/selectDate/selectDate', {
|
navTo('/packageA/pages/selectDate/selectDate', {
|
||||||
query: {
|
query: {
|
||||||
date: currentDay.value.fullDate,
|
date: currentDay.value.fullDate,
|
||||||
|
entrance: 'careerfair',
|
||||||
},
|
},
|
||||||
onBack: (res) => {
|
onBack: (res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
@@ -162,12 +177,11 @@ function seemsg(index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleScrollToLower = () => {
|
const handleScrollToLower = () => {
|
||||||
return
|
return;
|
||||||
getFair();
|
getFair();
|
||||||
console.log('触底');
|
console.log('触底');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function getFair(type = 'add') {
|
function getFair(type = 'add') {
|
||||||
if (type === 'refresh') {
|
if (type === 'refresh') {
|
||||||
pageState.page = 1;
|
pageState.page = 1;
|
||||||
@@ -177,7 +191,7 @@ function getFair(type = 'add') {
|
|||||||
pageState.page += 1;
|
pageState.page += 1;
|
||||||
}
|
}
|
||||||
let params = {
|
let params = {
|
||||||
zphmc:pageState.zphmc,
|
zphmc: pageState.zphmc,
|
||||||
// current: pageState.page,
|
// current: pageState.page,
|
||||||
// pageSize: pageState.pageSize,
|
// pageSize: pageState.pageSize,
|
||||||
};
|
};
|
||||||
@@ -194,7 +208,7 @@ function getFair(type = 'add') {
|
|||||||
// const end = fairList.value.length;
|
// const end = fairList.value.length;
|
||||||
// const reslist = rows;
|
// const reslist = rows;
|
||||||
// fairList.value.splice(str, end, ...reslist);
|
// fairList.value.splice(str, end, ...reslist);
|
||||||
fairList.value = rows
|
fairList.value = rows;
|
||||||
} else {
|
} else {
|
||||||
fairList.value = rows;
|
fairList.value = rows;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
// BaseStore.js - 基础Store类
|
|
||||||
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
|
|
||||||
// import UniStorageHelper from '../common/UniStorageHelper'
|
|
||||||
import useChatGroupDBStore from './userChatGroupStore'
|
|
||||||
import config from '@/config'
|
|
||||||
|
|
||||||
|
|
||||||
class BaseStore {
|
|
||||||
db = null
|
|
||||||
isDBReady = false
|
|
||||||
dbName = 'BrowsingHistory'
|
|
||||||
constructor() {
|
|
||||||
this.checkAndInitDB()
|
|
||||||
}
|
|
||||||
checkAndInitDB() {
|
|
||||||
// 获取本地数据库版本
|
|
||||||
if (config.OnlyUseCachedDB) {
|
|
||||||
return this.initDB()
|
|
||||||
}
|
|
||||||
const localVersion = uni.getStorageSync('indexedDBVersion') || 1
|
|
||||||
console.log('DBVersion: ', localVersion, config.DBversion)
|
|
||||||
if (localVersion === config.DBversion) {
|
|
||||||
this.initDB()
|
|
||||||
} else {
|
|
||||||
console.log('清空本地数据库')
|
|
||||||
this.clearDB().then(() => {
|
|
||||||
uni.setStorageSync('indexedDBVersion', config.DBversion);
|
|
||||||
this.initDB();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
initDB() {
|
|
||||||
// // #ifdef H5
|
|
||||||
this.db = new IndexedDBHelper(this.dbName, config.DBversion);
|
|
||||||
// // #endif
|
|
||||||
// // #ifndef H5
|
|
||||||
// this.db = new UniStorageHelper(this.dbName, config.DBversion);
|
|
||||||
// // #endif
|
|
||||||
this.db.openDB([{
|
|
||||||
name: 'record',
|
|
||||||
keyPath: "id",
|
|
||||||
autoIncrement: true,
|
|
||||||
}, {
|
|
||||||
name: 'messageGroup',
|
|
||||||
keyPath: "id",
|
|
||||||
autoIncrement: true,
|
|
||||||
}, {
|
|
||||||
name: 'messages',
|
|
||||||
keyPath: "id",
|
|
||||||
autoIncrement: true,
|
|
||||||
indexes: [{
|
|
||||||
name: 'parentGroupId',
|
|
||||||
key: 'parentGroupId',
|
|
||||||
unique: false
|
|
||||||
}]
|
|
||||||
}]).then(async () => {
|
|
||||||
useChatGroupDBStore().init()
|
|
||||||
this.isDBReady = true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
async clearDB() {
|
|
||||||
return new Promise((resolve, rejetc) => {
|
|
||||||
new IndexedDBHelper().deleteDB(this.dbName).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseDB = new BaseStore()
|
|
||||||
|
|
||||||
export default baseDB
|
|
||||||
@@ -9,7 +9,7 @@ import jobAnalyzer from '@/utils/jobAnalyzer';
|
|||||||
import {
|
import {
|
||||||
msg
|
msg
|
||||||
} from '@/common/globalFunction.js'
|
} from '@/common/globalFunction.js'
|
||||||
import baseDB from './BaseDBStore';
|
import baseDB from '@/utils/db.js';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
|
||||||
class JobRecommendation {
|
class JobRecommendation {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
ref,
|
ref,
|
||||||
toRaw
|
toRaw
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
import baseDB from './BaseDBStore';
|
import baseDB from '@/utils/db.js';
|
||||||
import {
|
import {
|
||||||
msg,
|
msg,
|
||||||
CloneDeep,
|
CloneDeep,
|
||||||
|
|||||||
91
utils/db.js
Normal file
91
utils/db.js
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// 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'
|
||||||
|
initPromise = null
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.initPromise = this.checkAndInitDB()
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDB() {
|
||||||
|
if (!this.initPromise) {
|
||||||
|
this.initPromise = this.checkAndInitDB();
|
||||||
|
}
|
||||||
|
await this.initPromise; // 等待初始化完成
|
||||||
|
return this.db;
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkAndInitDB() {
|
||||||
|
if (config.OnlyUseCachedDB) {
|
||||||
|
return this.initDB()
|
||||||
|
}
|
||||||
|
const localVersion = uni.getStorageSync('indexedDBVersion') || 1
|
||||||
|
console.log('DBVersion: ', localVersion, config.DBversion)
|
||||||
|
if (localVersion === config.DBversion) {
|
||||||
|
return this.initDB() // 🟢 记得加 return
|
||||||
|
} else {
|
||||||
|
console.log('清空本地数据库')
|
||||||
|
await this.clearDB() // 🟢 建议用 await
|
||||||
|
uni.setStorageSync('indexedDBVersion', config.DBversion);
|
||||||
|
return this.initDB(); // 🟢 记得加 return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initDB() {
|
||||||
|
// // #ifdef H5
|
||||||
|
this.db = new IndexedDBHelper(this.dbName, config.DBversion);
|
||||||
|
// // #endif
|
||||||
|
|
||||||
|
return this.db.openDB([{
|
||||||
|
name: 'record',
|
||||||
|
keyPath: "id",
|
||||||
|
autoIncrement: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'messageGroup',
|
||||||
|
keyPath: "id",
|
||||||
|
autoIncrement: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'messages',
|
||||||
|
keyPath: "id",
|
||||||
|
autoIncrement: true,
|
||||||
|
indexes: [{
|
||||||
|
name: 'parentGroupId',
|
||||||
|
key: 'parentGroupId',
|
||||||
|
unique: false
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'api_cache',
|
||||||
|
keyPath: "cacheKey", // 使用 URL+参数 作为主键
|
||||||
|
indexes: []
|
||||||
|
}
|
||||||
|
]).then(async () => {
|
||||||
|
// 这里原来的逻辑保留
|
||||||
|
if (useChatGroupDBStore) {
|
||||||
|
useChatGroupDBStore().init()
|
||||||
|
}
|
||||||
|
this.isDBReady = true
|
||||||
|
return this.db;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearDB() {
|
||||||
|
return new Promise((resolve, rejetc) => {
|
||||||
|
new IndexedDBHelper().deleteDB(this.dbName).then(() => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseDB = new BaseStore()
|
||||||
|
export default baseDB
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
import config from "@/config.js"
|
import config from "@/config.js"
|
||||||
import {
|
import {
|
||||||
sm2_Decrypt,
|
sm2_Decrypt,
|
||||||
sm2_Encrypt
|
sm2_Encrypt,
|
||||||
} from '@/common/globalFunction';
|
|
||||||
import useUserStore from '@/stores/useUserStore';
|
|
||||||
import {
|
|
||||||
sm4Decrypt,
|
sm4Decrypt,
|
||||||
sm4Encrypt
|
sm4Encrypt
|
||||||
} from '../common/globalFunction';
|
} from '@/common/globalFunction';
|
||||||
|
import IndexedDBHelper from '@/common/IndexedDBHelper';
|
||||||
|
import useUserStore from '@/stores/useUserStore';
|
||||||
|
import baseDB from '@/utils/db.js';
|
||||||
|
|
||||||
|
const CACHE_STORE_NAME = 'api_cache';
|
||||||
|
|
||||||
const needToEncrypt = [
|
const needToEncrypt = [
|
||||||
["post", "/app/login"],
|
["post", "/app/login"],
|
||||||
@@ -20,6 +21,47 @@ const needToEncrypt = [
|
|||||||
["get", "/app/user/experience/list"]
|
["get", "/app/user/experience/list"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带缓存的请求方法
|
||||||
|
*/
|
||||||
|
export async function createRequestWithCache(url, data = {}, method = 'GET', loading = false, headers = {},
|
||||||
|
onCacheLoad = null) {
|
||||||
|
const cacheKey = `${method.toUpperCase()}:${url}:${JSON.stringify(data)}`;
|
||||||
|
|
||||||
|
baseDB.getDB().then(async (dbHelper) => {
|
||||||
|
try {
|
||||||
|
const cachedRecord = await dbHelper.get(CACHE_STORE_NAME, cacheKey);
|
||||||
|
|
||||||
|
if (cachedRecord && cachedRecord.response && typeof onCacheLoad === 'function') {
|
||||||
|
onCacheLoad(cachedRecord.response);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('读取缓存失败', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. 发起网络请求
|
||||||
|
try {
|
||||||
|
const networkResponse = await createRequest(url, data, method, loading, headers);
|
||||||
|
baseDB.getDB().then(async (dbHelper) => {
|
||||||
|
try {
|
||||||
|
await dbHelper.update(CACHE_STORE_NAME, {
|
||||||
|
cacheKey: cacheKey,
|
||||||
|
response: networkResponse,
|
||||||
|
timestamp: Date.now()
|
||||||
|
});
|
||||||
|
console.log('💾 [BaseDB] 缓存更新:', url);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('更新缓存失败', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return networkResponse;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param url String,请求的地址,默认:none
|
* @param url String,请求的地址,默认:none
|
||||||
* @param data Object,请求的参数,默认:{}
|
* @param data Object,请求的参数,默认:{}
|
||||||
|
|||||||
Reference in New Issue
Block a user