Browse Source

全局馆代码处理

master
xuhuajiao 3 weeks ago
parent
commit
fd03424e1e
  1. 85
      App.vue
  2. 8
      api/user.js
  3. 61
      pages/home/home.vue
  4. 2
      pages/lendCar/lendCar.vue
  5. 6
      pages/login/login.vue
  6. 4
      pages/search/search.vue
  7. 2
      pages/user/user.vue
  8. 15
      subpkg/pages/activity-detail/activity-detail.vue
  9. 6
      subpkg/pages/activity-record/activity-record.vue
  10. 8
      subpkg/pages/agreement/agreement.vue
  11. 6
      subpkg/pages/book-detail/book-detail.vue
  12. 9
      subpkg/pages/book-list/book-list.vue
  13. 12
      subpkg/pages/collect-list/collect-list.vue
  14. 4
      subpkg/pages/feedback-detail/feedback-detail.vue
  15. 6
      subpkg/pages/feedback-list/feedback-list.vue
  16. 13
      subpkg/pages/feedback/feedback.vue
  17. 20
      subpkg/pages/myLending/myLending.vue
  18. 10
      subpkg/pages/ranking/ranking.vue
  19. 24
      subpkg/pages/reader-card/reader-card.vue
  20. 6
      subpkg/pages/register/register-form.vue
  21. 2
      subpkg/pages/register/register.vue
  22. 60
      subpkg/pages/seat-booking/seat-booking.vue
  23. 9
      subpkg/pages/seat-record/seat-record.vue
  24. 10
      subpkg/pages/user-info/user-info.vue
  25. 1
      utils/config.js
  26. 18
      utils/global.js
  27. 6
      utils/storage.js

85
App.vue

@ -1,32 +1,71 @@
<script>
import { FetchLibcodeBycode } from '@/api/user'
export default {
onLaunch: function() {
console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
console.log('App Launch')
globalData: {
appid: '',
libcode: '', // libcode getApp().globalData.libcode 访
},
onShow: function() {
console.log('App Show')
onLaunch() {
this.initAppIdAndLibcode()
},
onHide: function() {
console.log('App Hide')
methods: {
// appid libcodeglobalData
async initAppIdAndLibcode() {
// #ifdef MP-WEIXIN
try {
// 1appid
const accountInfo = wx.getAccountInfoSync()
const appid = accountInfo.miniProgram.appId
this.globalData.appid = appid
// libcode
let cacheLibcode = uni.getStorageSync('GLOBAL_LIBCODE')
if(cacheLibcode){
this.globalData.libcode = cacheLibcode
console.log('使用缓存libcode:', cacheLibcode)
return
}
// 2 FetchLibcodeBycodeappidlibcode
const res = await FetchLibcodeBycode({
code: 'vx_mini_appId',
value: appid
})
if(res.code === 200 && res.data){
const libcode = res.data
this.globalData.libcode = libcode
uni.setStorageSync('GLOBAL_LIBCODE', libcode)
console.log('接口获取全局libcode成功:', libcode)
}else{
console.error('FetchLibcodeBycode 获取libcode失败', res)
}
</script>
<style lang="scss">
/*每个页面公共css */
@import '@/uni_modules/uni-scss/index.scss';
/* #ifndef APP-NVUE */
@import '@/static/customicons.css';
//
page {
background-color: #f5f5f5;
} catch(e){
console.error('初始化appid/libcode异常', e)
}
// #endif
},
// 退
// logout(){
// // 1.
// uni.removeStorageSync('wx_login_code')
// uni.removeStorageSync('READER_CARD_LIST')
// uni.removeStorageSync('CURRENT_READER_CARD')
// // 2.libcode
// uni.removeStorageSync('GLOBAL_LIBCODE')
// getApp().globalData.libcode = ''
/* #endif */
.example-info {
font-size: 14px;
color: #333;
padding: 10px;
// //
// uni.reLaunch({url:'/pages/login/login'})
// }
// libcode
// refreshLibcode(){
// uni.removeStorageSync('GLOBAL_LIBCODE')
// getApp().globalData.libcode = ''
// uni.showToast({title:"libcode",icon:"none"})
// // App.vue
// getApp().$options.methods.initAppIdAndLibcode()
// }
}
</style>
}
</script>

8
api/user.js

@ -183,3 +183,11 @@ export function FetchMsgSecCheck(data) {
data
});
}
// 根据微信code 获取馆代码
export function FetchLibcodeBycode(data) {
return request({
url: '/api/screenSetting/getLibcodeBycode',
data
});
}

61
pages/home/home.vue

@ -237,6 +237,7 @@ import { FetchInitScreenSetting, FetchOpenId, FetchFindAllReaderBindByOpenId} fr
import { FetchInitScreenBookRecommend } from '@/api/book';
import config from '@/utils/config';
import { STORAGE_KEYS } from '@/utils/storage';
import { waitLibcodeReady } from '@/utils/global'
export default {
data() {
@ -255,16 +256,25 @@ export default {
};
},
onLoad() {
this.getRecommendBooks();
this.getScreenSetting()
// this.getRecommendBooks();
// this.getScreenSetting()
this.initPage()
},
onShow() {
this.initUserAndCheckBind();
},
methods:{
async getScreenSetting() {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
async initPage(){
const libcode = await waitLibcodeReady()
if(!libcode){
uni.showToast({title:'获取图书馆编码失败',icon:'none'})
return
}
this.getRecommendBooks(libcode);
this.getScreenSetting(libcode)
},
async getScreenSetting(libcode) {
const res = await FetchInitScreenSetting({ libcode });
//
if (res.data.wechat_qr_code && res.data.wechat_qr_code.context) {
@ -310,17 +320,11 @@ export default {
}
this.$refs.erweimapopup.open()
},
//
formatCardNo(cardNo) {
if (!cardNo) return '';
const str = String(cardNo);
const len = str.length;
if (len > 8) {
// 2 + * + 2
const front = str.substring(0, 2);
@ -338,6 +342,8 @@ export default {
// openid
async initUserAndCheckBind() {
try {
const libcode = await waitLibcodeReady()
if(!libcode) return
// 1. openId
let openId = uni.getStorageSync('wx_login_code');
@ -350,43 +356,28 @@ export default {
});
});
if (!loginRes.code) {
uni.showToast({ title: '授权失败', icon: 'none' });
return;
}
// 3. openId
const openRes = await FetchOpenId({
libcode: config.LIB_CODE,
libcode,
code: loginRes.code
});
if (openRes.code !== 200 || !openRes.data) {
return;
}
openId = openRes.data;
uni.setStorageSync('wx_login_code', openId);
}
// 4. openId
const res = await FetchFindAllReaderBindByOpenId({
libcode: config.LIB_CODE,
libcode,
openId: openId
});
if (res.code === 200 && res.data.length > 0) {
this.isBindLibraryCard = true;
//
@ -404,8 +395,6 @@ export default {
uni.setStorageSync(STORAGE_KEYS.CURRENT_READER_CARD, null);
}
} catch (err) {
console.error('初始化失败:', err);
const list = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || [];
@ -413,20 +402,15 @@ export default {
const defaultCard = list.find(item => item.bindDefault === true);
const otherCards = list.filter(item => !item.bindDefault);
this.readerCardList = defaultCard ? [defaultCard, ...otherCards] : list;
this.isBindLibraryCard = list.length > 0;
}
},
// + base64
async getRecommendBooks() {
async getRecommendBooks(libcode) {
try {
const res = await FetchInitScreenBookRecommend({ libcode: config.LIB_CODE });
const res = await FetchInitScreenBookRecommend({ libcode });
let books = res.data || [];
// 3setData
const limit = 3;
const displayBooks = books.slice(0, limit);
@ -448,9 +432,6 @@ export default {
item.base64Cover = '';
}
}
// 3setData
this.recommendedBooks = displayBooks;
this.isLoading = false;

2
pages/lendCar/lendCar.vue

@ -140,7 +140,7 @@ export default {
* 获取屏幕配置
*/
async getScreenSetting() {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
this.screenConfig = {
thirdUrl: res.data.open_lib_http?.context || '',
thirdAppid: res.data.open_lib_appId?.context || '',

6
pages/login/login.vue

@ -134,7 +134,7 @@ export default {
async getScreenSetting() {
try {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
const data = res.data;
this.screenConfig = {
thirdUrl: data.open_lib_http?.context || '',
@ -211,7 +211,7 @@ export default {
openid: openId,
bindValue: this.queryvalue,
bindType: 'rdid',
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
}
//
const bindRes = await FetchBindReadCard(bindParams);
@ -225,7 +225,7 @@ export default {
icon: 'success'
});
const data = {
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId
}
FetchFindAllReaderBindByOpenId(data).then(res => {

4
pages/search/search.vue

@ -139,7 +139,7 @@ export default {
// opacUrl
async getOpacUrl() {
try {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
this.opacUrl = res.data.opac_url?.context || '';
} catch (err) {
console.error('获取配置失败', err);
@ -240,7 +240,7 @@ export default {
const openId = await getOpenId();
if (openId) {
const res = await FetchFindAllBookCollectionByOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId,
page: 0,
size: 100

2
pages/user/user.vue

@ -100,7 +100,7 @@ export default {
if (openId) {
const res = await FetchFindAllReaderByOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId
});

15
subpkg/pages/activity-detail/activity-detail.vue

@ -85,7 +85,7 @@
</template>
<script>
import config from '@/utils/config';
// import config from '@/utils/config';
// import { getOpenId } from '@/utils/storage';
import { FetchSessionKey, FetchDecryptPhone } from '@/api/user.js';
import { FetchSignActivity, FetchCancelSignActivity } from '@/api/activity.js';
@ -123,7 +123,6 @@ export default {
this.activityId = item.id || item.activityId;
this.formatContent();
this.rangeText = this.personOptions.map(item => item.text);
this.joinForm.personCount = this.personOptions[0].value;
this.joinForm.personCountText = this.personOptions[0].text;
@ -140,7 +139,6 @@ export default {
}
content = content.replace(/&amp;/g, '&');
// ========== ==========
const imgReg = /<img\s+[^>]*src\s*=\s*["']?([^"'> ]+)["']?[^>]*>/gi;
content = content.replace(imgReg, (match, src) => {
return `<div><img src="${src}" style="width:100%;max-width:750px;display:block;margin:0 auto;"></div>`;
@ -186,7 +184,7 @@ export default {
console.log('loginRes',loginRes)
if (loginRes.code) {
const res = await FetchSessionKey({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
code: loginRes.code
});
if (res.code === 200) {
@ -200,18 +198,15 @@ export default {
console.error('获取sessionKey失败:', error);
}
},
getPhoneNumber(e) {
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
uni.showToast({ title: '取消授权', icon: 'none' });
return;
}
if (!this.sessionKey) {
uni.showToast({ title: '请稍后再试', icon: 'none' });
return;
}
FetchDecryptPhone({
sessionKey: this.sessionKey,
encryptedData: e.detail.encryptedData,
@ -252,7 +247,6 @@ export default {
if (['已结束', '已取消'].includes(d.status)) {
return;
}
//
if(d.status === '未开始' && d.isCancel === false && !!d.signId){
uni.showModal({
@ -283,7 +277,6 @@ export default {
})
return
}
//
this.openJoinModal();
},
@ -318,7 +311,7 @@ export default {
return;
}
const params = {
// libcode: config.LIB_CODE,
// libcode: getApp().globalData.libcode,
activityId: this.activityId,
signName: this.joinForm.name,
signPhone: this.joinForm.phone,
@ -507,13 +500,11 @@ export default {
justify-content: space-between;
padding: 15px;
border-bottom: 1px solid #f0f0f0;
.modal-title {
font-size: 16px;
font-weight: bold;
color: #333;
}
.close-icon {
color: #999;
}

6
subpkg/pages/activity-record/activity-record.vue

@ -194,7 +194,7 @@ export default {
console.log('loginRes', loginRes)
if (loginRes.code) {
const res = await FetchSessionKey({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
code: loginRes.code
});
if (res.code === 200) {
@ -273,19 +273,15 @@ export default {
this.loading = false;
}
},
onRefresh() {
if(this.loading) return
this.getActivityList(true);
},
onScrollLower() {
if(this.loading || this.noMore) return;
this.page += 1;
this.getActivityList(false);
},
cancelAppoint(item) {
uni.showModal({
title: '提示',

8
subpkg/pages/agreement/agreement.vue

@ -206,14 +206,6 @@ export default {
padding: 12px;
}
.chapter {
// background-color: #fff;
// border-radius: 12rpx;
// padding: 30rpx;
// margin-bottom: 24rpx;
// box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
}
.chapter-title {
font-size: 30rpx;
font-weight: bold;

6
subpkg/pages/book-detail/book-detail.vue

@ -234,7 +234,7 @@ export default {
//
async getOpacUrl() {
try {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
this.opacUrl = res.data.opac_url?.context || '';
this.getDictionaryTree();
this.getBookDetail();
@ -257,7 +257,7 @@ export default {
this.bookInfo = apiData.biblios || {};
this.holdingsData = apiData.holdings || [];
// searchListInfo
// searchListInfo
if(!this.searchListInfo || !this.searchListInfo.bookrecno){
this.searchListInfo = {
bookrecno: this.bookInfo.bookrecno,
@ -353,7 +353,7 @@ export default {
const params = {
...this.searchListInfo,
openid: openId,
libcode: config.LIB_CODE
libcode: getApp().globalData.libcode
};
const res = await FetchCollectionBook(params);
if (res.code === 200) {

9
subpkg/pages/book-list/book-list.vue

@ -65,18 +65,16 @@ export default {
});
});
},
//
refresh() {
this.bookList = [];
this.noMore = false;
this.getBookRecommendList();
},
async getBookRecommendList() {
this.loading = true;
try {
const res = await FetchInitScreenBookRecommend({ libcode: config.LIB_CODE });
const res = await FetchInitScreenBookRecommend({ libcode: getApp().globalData.libcode });
let books = res.data || [];
// 1.
@ -100,26 +98,21 @@ export default {
uni.stopPullDownRefresh();
}
},
async loadImagesOneByOne() {
for (let i = 0; i < this.bookList.length; i++) {
let item = this.bookList[i];
if (!item.imgVxPath) continue;
//
// const url = this.baseUrl + '/api/fileRelevant/getImg?imgType=2&imgId=' + item.imgPath;
// const base64 = await this.urlToBase64(url);
const imageUrl = this.baseUrl + '/files/' + item.imgVxPath;
console.log('imageUrl:', imageUrl);
if (imageUrl) {
item.base64Cover = imageUrl;
this.$set(this.bookList, i, item); //
}
}
},
goToDetail(item) {
uni.navigateTo({
url: "/subpkg/pages/book-detail/book-detail?bookData=" + encodeURIComponent(JSON.stringify(item)) + "&fromRecommend=true"

12
subpkg/pages/collect-list/collect-list.vue

@ -27,7 +27,7 @@
import BookListItem from "@/components/book-list-item/book-list-item.vue";
import { FetchFindAllBookCollectionByOpenId } from '@/api/book';
import { getOpenId } from '@/utils/storage';
import config from '@/utils/config';
// import config from '@/utils/config';
import { loadBookCoversBase64 } from '@/utils/bookCover';
export default {
@ -44,7 +44,6 @@ export default {
hasLoadedAll: false,
}
},
onLoad() {
},
onShow() {
@ -79,7 +78,7 @@ export default {
}
const res = await FetchFindAllBookCollectionByOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId,
page: this.pageNum,
size: this.pageSize,
@ -102,7 +101,6 @@ export default {
this.isLoading = false;
}
},
async refreshData() {
this.pageNum = 0;
this.noMore = false;
@ -115,10 +113,8 @@ export default {
});
uni.stopPullDownRefresh();
},
async loadMore() {
if (this.noMore || this.isLoading) return;
this.pageNum++;
this.isLoading = true;
@ -129,14 +125,12 @@ export default {
this.isLoading = false;
return;
}
const res = await FetchFindAllBookCollectionByOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId,
page: this.pageNum,
size: this.pageSize,
});
if (res.code === 200) {
const newData = res.data.content || [];
this.bookCollectList = [...this.bookCollectList, ...newData];

4
subpkg/pages/feedback-detail/feedback-detail.vue

@ -17,7 +17,6 @@
<script>
import { FetchReaderMessageDetailsById } from '@/api/user';
export default {
data() {
return {
@ -38,13 +37,10 @@ export default {
console.warn('缺少留言 ID');
return;
}
const res = await FetchReaderMessageDetailsById({
id: this.detail.id
});
console.log(res);
if (res && res.code === 200) {
this.detail = res.data || {};
} else {

6
subpkg/pages/feedback-list/feedback-list.vue

@ -37,7 +37,7 @@
<script>
import { FetchInitReaderMessage } from '@/api/user';
import config from '@/utils/config';
// import config from '@/utils/config';
import { getOpenId } from '@/utils/storage';
export default {
@ -71,7 +71,7 @@ export default {
}
// const currentReaderCard = await getCurrentReaderCard();
const res = await FetchInitReaderMessage({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId,
// readCardNo: currentReaderCard.readCardNo,
// readName: '',
@ -123,7 +123,7 @@ export default {
}
const res = await FetchInitReaderMessage({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId,
page: this.pageNum,
size: this.pageSize,

13
subpkg/pages/feedback/feedback.vue

@ -54,9 +54,8 @@
<script>
import { FetchReaderMessage,FetchAccessToken,FetchMsgSecCheck } from '@/api/user';
import config from '@/utils/config';
// import config from '@/utils/config';
import { getCurrentReaderCard,getOpenId } from '@/utils/storage';
const USER_KEY = 'user-info';
export default {
@ -87,7 +86,6 @@ export default {
console.error('获取读者证信息失败:', err);
}
},
loadUserInfo() {
const userInfo = uni.getStorageSync(USER_KEY) || {};
if (userInfo.nickname) {
@ -95,12 +93,10 @@ export default {
this.hasNickname = true;
}
},
validatePhone(phone) {
const phoneReg = /^1[3-9]\d{9}$/;
return phoneReg.test(phone);
},
async onBtnClick() {
const { name, readerCard, subject, phone, content } = this.formData;
@ -151,7 +147,6 @@ export default {
});
return;
}
uni.showLoading({
title: '提交中'
});
@ -163,7 +158,7 @@ export default {
}
// 1. access_token
const tokenRes = await FetchAccessToken({ libcode: config.LIB_CODE });
const tokenRes = await FetchAccessToken({ libcode: getApp().globalData.libcode });
if (!tokenRes || tokenRes.code !== 200 || !tokenRes.data) {
uni.showToast({ title: '获取访问令牌失败', icon: 'none' });
return;
@ -172,7 +167,7 @@ export default {
// 2.
const secCheckRes = await FetchMsgSecCheck({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
content: content,
version: 2,
scene: 2,
@ -232,7 +227,7 @@ export default {
// 3.
const res = await FetchReaderMessage({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openid: openId,
phone,
readCardNo: readerCard,

20
subpkg/pages/myLending/myLending.vue

@ -71,7 +71,7 @@ import { FetchHistoryloan, FetchRdloanlist, FetchCoverByISBN } from '@/api/book'
import myTabs from "@/components/my-tabs/my-tabs.vue";
import lendingListItem from "@/components/lending-list-item/lending-list-item.vue";
import { getCurrentReaderCard } from '@/utils/storage';
import config from '@/utils/config';
// import config from '@/utils/config';
import { loadBookCoversBase64 } from '@/utils/bookCover';
export default {
@ -84,27 +84,22 @@ export default {
{ label: '历史借阅', status: 'all' },
],
currentIndex: 0,
//
allList: [],
loadingAll: false,
pageAll: 1,
hasMoreAll: true,
loadMoreStatusAll: '',
//
lendingList: [],
loadingLending: false,
swiperHeightData: {},
currentSwiperHeight: 400,
};
},
onLoad() {
this.getScreenSetting();
},
onShow() {
const tabIndex = uni.getStorageSync('switch_tab_index');
if (tabIndex !== '') {
@ -112,7 +107,6 @@ export default {
uni.removeStorageSync('switch_tab_index');
}
},
onPullDownRefresh() {
if (this.currentIndex === 0) {
this.getLendingList();
@ -120,7 +114,6 @@ export default {
this.getAllList(true);
}
},
onReachBottom() {
if (this.currentIndex === 0) {
this.getLendingList();
@ -128,11 +121,10 @@ export default {
this.getAllList();
}
},
methods: {
async getScreenSetting() {
try {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
const data = res.data;
this.screenConfig = {
thirdUrl: data.open_lib_http?.context || '',
@ -140,12 +132,10 @@ export default {
thirdSecret: data.open_lib_secret?.context || '',
sm4Key: data.sm4_key?.context || ''
};
// tab
this.getLendingList(true);
} catch (err) {}
},
async getAllList(isRefresh = false) {
if (this.loadingAll) return;
this.loadingAll = true;
@ -190,7 +180,6 @@ export default {
}, 100);
}
},
async getLendingList() {
this.loadingLending = true;
try {
@ -222,7 +211,6 @@ export default {
}, 100);
}
},
//
async loadCoversForList(list) {
await loadBookCoversBase64(list, (index, coverUrl) => {
@ -231,7 +219,6 @@ export default {
}
});
},
//
calcHeight(type) {
const selector = `.list-item-${type}`;
@ -247,7 +234,6 @@ export default {
this.currentSwiperHeight = totalHeight + 20;
}).exec();
},
tabClick(index) {
this.currentIndex = index;
if (index === 0) {
@ -264,11 +250,9 @@ export default {
}
}
},
onSwiperChange(e) {
if (e.detail.source === 'touch') this.currentIndex = e.detail.current;
},
onSwiperEnd() {
this.tabClick(this.currentIndex);
},

10
subpkg/pages/ranking/ranking.vue

@ -78,8 +78,8 @@
<script>
import { FetchInitScreenSetting } from '@/api/user';
import { FetchBookRanking } from '@/api/book';
import config from '@/utils/config';
import { loadBookCoversBase64 } from '@/utils/bookCover';
// import config from '@/utils/config';
export default {
data() {
@ -89,21 +89,18 @@ export default {
loading: true,
};
},
onLoad() {
this.getScreenSetting();
},
methods: {
async getScreenSetting() {
try {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
this.getReadRanking(res.data);
} catch (err) {
console.error('获取屏幕配置失败:', err);
}
},
getFormattedDate(date) {
const year = date.getFullYear();
const month = date.getMonth() + 1;
@ -120,7 +117,7 @@ export default {
const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
const params = {
'libcode': 'GD',
'libcode': getApp().globalData.libcode,
'starttime': formattedDate,
'endtime': this.getFormattedDate(new Date()),
'rownum': 10,
@ -150,7 +147,6 @@ export default {
this.loading = false;
})
},
//
async loadCoversForList() {
await loadBookCoversBase64(this.rankingData, (index, coverUrl) => {

24
subpkg/pages/reader-card/reader-card.vue

@ -1,7 +1,6 @@
<template>
<view class="reader-card">
<image class="card-top-bg" src="/subpkg/static/card-img1.png" mode="widthFix" />
<view class="edit-btn" @click="toggleEditMode">
{{ isEditMode ? '完成' : '解绑' }}
</view>
@ -69,13 +68,10 @@
</template>
<script>
import {
FetchFindAllReaderBindByOpenId,
FetchSetDefaultReadCard,
FetchUnbindReadCard
} from '@/api/user';
// FetchFindAllReaderBindByOpenId,
import { FetchSetDefaultReadCard, FetchUnbindReadCard } from '@/api/user';
import { getReaderCardList, getOpenId, setCurrentReaderCard, clearReaderCardCache, STORAGE_KEYS } from '@/utils/storage';
import config from '@/utils/config';
// import config from '@/utils/config';
export default {
data() {
@ -105,12 +101,10 @@ export default {
return '***' + str.substring(len - 2);
}
},
toggleEditMode() {
this.isEditMode = !this.isEditMode;
this.selectedValue = '';
},
async getBindReaderCardList(forceRefresh = false) {
if (this.loading) return;
this.loading = true;
@ -126,13 +120,11 @@ export default {
this.loading = false;
}
},
handleSelectItem(value) {
if (this.isEditMode) {
this.selectedValue = this.selectedValue === value ? '' : value;
}
},
async setDefaultCard(value) {
const currentDefault = this.cardList.find(item => item.bindDefault === true);
if (currentDefault && currentDefault.bindValue === value) {
@ -155,7 +147,7 @@ export default {
await FetchSetDefaultReadCard({
bindType: 'rdid',
bindValue: value,
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openid: openId
});
setCurrentReaderCard(value);
@ -168,17 +160,14 @@ export default {
}
});
},
showQrcode(bindValue) {
this.qrcodeText = bindValue;
this.$refs.popup.open();
},
closePopup() {
this.qrcodeText = '';
this.$refs.popup.close();
},
async handleUnbind() {
if (!this.selectedValue) {
uni.showToast({ title: '请选择要解绑的读者证', icon: 'none' });
@ -204,7 +193,7 @@ export default {
const result = await FetchUnbindReadCard({
bindType: "rdid",
bindValue: this.selectedValue,
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openid: openId
});
@ -218,7 +207,7 @@ export default {
await FetchSetDefaultReadCard({
bindType: 'rdid',
bindValue: newValue,
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openid: openId
});
setCurrentReaderCard(newValue);
@ -237,7 +226,6 @@ export default {
}
});
},
toAddReaderCard() {
uni.navigateTo({ url: "/pages/login/login" });
},

6
subpkg/pages/register/register-form.vue

@ -152,7 +152,7 @@ export default {
console.log('loginRes',loginRes)
if (loginRes.code) {
const res = await FetchSessionKey({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
code: loginRes.code
});
if (res.code === 200) {
@ -167,7 +167,7 @@ export default {
}
},
async getScreenSetting() {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
if(res.data.library_logo && res.data.library_logo.context){
this.libraryLogo = config.baseUrl + '/files/' + res.data.library_logo.context;
@ -352,7 +352,7 @@ export default {
// phone: this.formData.phone.trim(),
// password: this.formData.password,
// openId,
// libcode: config.LIB_CODE
// libcode: getApp().globalData.libcode
// }
// });

2
subpkg/pages/register/register.vue

@ -67,7 +67,7 @@ export default {
},
methods: {
async getScreenSetting() {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
if(res.data.library_logo && res.data.library_logo.context){
this.libraryLogo = config.baseUrl + '/files/' + res.data.library_logo.context;

60
subpkg/pages/seat-booking/seat-booking.vue

@ -37,7 +37,6 @@
</view>
</view>
<!-- 时间选择闭馆时整体禁用 -->
<view class="section" :class="{disabled: isSelectCloseDay}">
<view class="section-title">时间选择</view>
@ -75,7 +74,6 @@
<view class="notice-content">{{ closeNoticeText }}</view>
</view>
<view class="section operate-desc">
<view class="section-title" style="font-size: 14px;">预约说明</view>
<view class="desc-item">
@ -106,8 +104,7 @@
<script>
import { FetchInitLibraryReservationSettings, FetchInitMyReservation,FetchReserve } from '@/api/reservation';
import { getOpenId } from '@/utils/storage';
import config from '@/utils/config';
// import config from '@/utils/config';
export default {
data() {
@ -208,7 +205,7 @@ export default {
try {
const openId = await getOpenId();
const res = await FetchInitMyReservation({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId
})
console.log('初始化我的预约',res)
@ -294,13 +291,11 @@ export default {
weekDays
}
},
//
async initReservationSettings() {
try {
const res = await FetchInitLibraryReservationSettings({
libcode: config.LIB_CODE
libcode: getApp().globalData.libcode
})
if (res && res.code === 200 && res.data) {
this.reserveConfig = this.transformReserveConfig(res.data);
@ -311,8 +306,6 @@ export default {
console.error('获取预约设置异常', e)
}
},
getWeekNum(dateStr) {
const d = new Date(dateStr);
const day = d.getDay();
@ -322,8 +315,6 @@ export default {
const map = {1:'周一',2:'周二',3:'周三',4:'周四',5:'周五',6:'周六',7:'周日'}
return map[weekNo]
},
generateCalendar() {
if(!this.reserveConfig) return;
const today = new Date();
@ -337,19 +328,14 @@ export default {
allowDateList.push(ds)
}
const list = []
allowDateList.forEach(dateStr=>{
const weekNo = this.getWeekNum(dateStr)
const weekCfg = this.reserveConfig.weekDays.find(w => w.id === weekNo)
const available = !!weekCfg?.checked
const d = new Date(dateStr)
const tempClose = this.tempCloseDateList.includes(dateStr)
const userHasBooked = this.userBookedDateList.includes(dateStr)
list.push({
day: d.getDate(),
date: dateStr,
@ -402,8 +388,6 @@ export default {
//
this.selectedTimeList = [...bookedTimeArr]
},
selectDate(day) {
//
if (!day.available && !day.tempClose) {
@ -429,7 +413,6 @@ export default {
return
}
const idx = this.selectedTimeList.indexOf(slot.time)
if(idx > -1){
//
@ -447,19 +430,13 @@ export default {
uni.showToast({ title: '请选择日期', icon: 'none' });
return;
}
const bookedTimeArr = this.userBookedMap[this.selectedDate] || []
//
const newSelectTimes = this.selectedTimeList.filter(item=> !bookedTimeArr.includes(item))
if (!newSelectTimes || newSelectTimes.length === 0) {
uni.showToast({ title: '请选择需要新增预约的时间段', icon: 'none' });
return;
}
uni.showLoading({ title: '预约中...' });
const openId = await getOpenId();
if (!openId) {
@ -467,28 +444,22 @@ export default {
uni.showToast({ title: '获取用户openid失败', icon: 'none' });
return;
}
//
const param = newSelectTimes.map(timeStr => {
const [startPart, endPart] = timeStr.split(' - ');
const startTime = startPart.trim() + ':00';
const endTime = endPart.trim() + ':00';
return {
libcode: config.LIB_CODE, //
libcode: getApp().globalData.libcode, //
openid: openId, // OpenID
specificDate: this.selectedDate, //
startTime: startTime, //
endTime: endTime //
}
})
try {
const res = await FetchReserve(param);
uni.hideLoading();
if(res.code === 200){
//
if(!this.userBookedDateList.includes(this.selectedDate)){
@ -497,7 +468,6 @@ export default {
const old = this.userBookedMap[this.selectedDate] || []
this.userBookedMap[this.selectedDate] = [...new Set([...old,...newSelectTimes])]
const timeText = newSelectTimes.map(t=>this.formatShowTime(t)).join('\n');
uni.showModal({
title: '预约成功',
@ -536,7 +506,6 @@ export default {
padding-bottom: 70px;
}
.section {
background-color: #fff;
margin: 10px;
@ -559,7 +528,6 @@ export default {
}
}
//
.section.disabled{
opacity:0.55;
@ -572,7 +540,6 @@ export default {
text-align:center;
}
.calendar-wrap{
background:#ffffff;
border-radius:16px;
@ -594,7 +561,6 @@ export default {
font-weight:bold;
}
.calendar-days-grid{
display:flex;
flex-wrap:wrap;
@ -613,7 +579,6 @@ export default {
overflow: hidden;
}
/* 今天左上角蓝色三角 */
.corner-block-today{
position:absolute;
@ -635,7 +600,6 @@ export default {
border-right: 12px solid transparent;
}
.card-week{
font-size:12px;
color:#666;
@ -651,7 +615,6 @@ export default {
margin-top:4px;
}
/* 可预约 */
.day-card.card-available{
background:#e8f4fd;
@ -659,8 +622,6 @@ export default {
.day-card.card-available .card-status{
color:#01a4fe;
}
/* 闭馆/不可选 */
.day-card.card-disabled{
background:#f7f8fa;
@ -670,8 +631,6 @@ export default {
.day-card.card-disabled .card-status{
color:#999;
}
/* 选中状态 */
.day-card.card-selected{
background:#01a4fe;
@ -689,8 +648,6 @@ export default {
.day-card.card-user-booked .card-status{
color:#ff7800;
}
.day-card.card-user-booked.card-selected{
background:#ff7800;
}
@ -699,26 +656,17 @@ export default {
.day-card.card-user-booked.card-selected .card-status{
color:#fff;
}
.day-card.card-temp-close .card-status{
color:#999;
}
.day-card.card-temp-close.card-selected {
background:#888;
}
.day-card.card-temp-close.card-selected .card-week,
.day-card.card-temp-close.card-selected .card-num,
.day-card.card-temp-close.card-selected .card-status{
color:#fff;
}
/* 时间选择 */
.section-title {
font-size: 16px;

9
subpkg/pages/seat-record/seat-record.vue

@ -80,7 +80,7 @@
<script>
import { FetchMyReservation, FetchCancelReservation } from '@/api/reservation';
import { getOpenId } from '@/utils/storage';
import config from '@/utils/config';
// import config from '@/utils/config';
export default {
data() {
@ -114,10 +114,8 @@ export default {
// 0
const todayTs = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()
const oneDay = 24 * 60 * 60 * 1000
const target = new Date(dateStr)
const targetTs = new Date(target.getFullYear(), target.getMonth(), target.getDate()).getTime()
const diffDay = Math.round((targetTs - todayTs) / oneDay)
if(diffDay === 0){
@ -152,7 +150,7 @@ export default {
async fetchMyReservation() {
const openId = await getOpenId();
const res = await FetchMyReservation({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId,
page: this.page,
size: this.pageSize,
@ -183,7 +181,6 @@ export default {
}
return { list: [], noMore: true }
},
async getActivityList(isRefresh = false) {
if (this.loading) return;
if (isRefresh) {
@ -211,13 +208,11 @@ export default {
this.loading = false;
}
},
onScrollLower() {
if (this.loading || this.noMore) return;
this.page += 1;
this.getActivityList(false);
},
async cancelAppoint(item) {
uni.showModal({
title: '提示',

10
subpkg/pages/user-info/user-info.vue

@ -33,7 +33,6 @@
<script>
import config from '@/utils/config'
import { FetchBindRead } from '@/api/user';
const USER_KEY = 'user-info';
export default {
@ -76,8 +75,6 @@ export default {
this.imgId = '';
}
},
// + + base64
async onChooseAvatar(e) {
const tempFilePath = e.detail.avatarUrl;
@ -99,13 +96,12 @@ export default {
const resData = JSON.parse(uploadRes.data);
const imgId = resData.data;
this.imgId = imgId;
// base64
// const url = `${config.baseUrl}/api/fileRelevant/getImg?imgType=5&imgId=${imgId}`;
const url = `${config.baseUrl}/files/${imgId}`;
// this.avatarUrl = await this.urlToBase64(url);
this.avatarUrl = url
const url = `${config.baseUrl}/files/${imgId}`;
this.avatarUrl = url
uni.showToast({ title: '头像上传成功', icon: 'success' });
} catch (err) {
console.error(err);
@ -149,7 +145,7 @@ export default {
const openId = uni.getStorageSync('wx_login_code') || '';
const params = {
avatar: this.imgId,
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
nickname: this.nickname,
openid: openId
};

1
utils/config.js

@ -3,7 +3,6 @@ const config = {
// baseUrl: 'http://192.168.99.63:14000',
// 线上
baseUrl: 'https://wechatapi.aiyxlib.com',
LIB_CODE: 'GD'
};
export default config;

18
utils/global.js

@ -0,0 +1,18 @@
// utils/global.js
export function waitLibcodeReady(){
return new Promise((resolve)=>{
const app = getApp()
if(app.globalData.libcode){
return resolve(app.globalData.libcode)
}
// 轮询等待,最多3秒
let count = 0
const timer = setInterval(()=>{
count++
if(app.globalData.libcode || count>30){
clearInterval(timer)
resolve(app.globalData.libcode || '')
}
},100)
})
}

6
utils/storage.js

@ -42,7 +42,7 @@ export async function getOpenId() {
// 4. 获取 openId
const openRes = await FetchOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
code: loginRes.code
});
@ -85,7 +85,7 @@ export async function getCurrentReaderCard() {
}
const res = await FetchFindAllReaderBindByOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId
});
@ -137,7 +137,7 @@ export async function getReaderCardList(forceRefresh = false) {
}
const res = await FetchFindAllReaderBindByOpenId({
libcode: config.LIB_CODE,
libcode: getApp().globalData.libcode,
openId: openId
});

Loading…
Cancel
Save