Browse Source

配置libcode,统一调取

master
xuhuajiao 1 month ago
parent
commit
1ddbfa615a
  1. 32
      App.vue
  2. 55
      api/user.js
  3. 7
      pages/home/home.vue
  4. 7
      pages/lendCar/lendCar.vue
  5. 20
      pages/login/login.vue
  6. 5
      pages/search/search.vue
  7. 6
      pages/user/user.vue
  8. 10
      subpkg/pages/book-detail/book-detail.vue
  9. 2
      subpkg/pages/book-list/book-list.vue
  10. 2
      subpkg/pages/feedback/feedback.vue
  11. 3
      subpkg/pages/myLending/myLending.vue
  12. 15
      subpkg/pages/ranking/ranking.vue
  13. 16
      subpkg/pages/reader-card/reader-card.vue
  14. 2
      subpkg/pages/user-info/user-info.vue
  15. 9
      utils/config.js
  16. 12
      utils/index.js
  17. 21
      utils/storage.js

32
App.vue

@ -1,19 +1,19 @@
<script>
export default {
<script>
export default {
onLaunch: function() { onLaunch: function() {
console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style lang="scss">
console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style lang="scss">
/*每个页面公共css */ /*每个页面公共css */
@import '@/uni_modules/uni-scss/index.scss'; @import '@/uni_modules/uni-scss/index.scss';
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
@ -28,5 +28,5 @@
font-size: 14px; font-size: 14px;
color: #333; color: #333;
padding: 10px; padding: 10px;
}
}
</style> </style>

55
api/user.js

@ -101,57 +101,4 @@ export function FetchUnbindReadCard(data) {
method: 'POST', method: 'POST',
data data
}); });
}
/**
* 用户登录
*/
export function login(data) {
return request({
url: '/sys/login',
method: 'POST',
data
});
}
/**
* 关注用户
*/
// export function userFollow(data) {
// return request({
// url: '/user/follow',
// data
// });
// }
/**
* 发表评论
*/
// export function userArticleComment(data) {
// return request({
// url: '/user/article/comment',
// method: 'POST',
// data
// });
// }
/**
* 用户点赞
*/
// export function userPraise(data) {
// return request({
// url: '/user/praise',
// data
// });
// }
/**
* 用户收藏
*/
// export function userCollect(data) {
// return request({
// url: '/user/collect',
// data
// });
// }
}

7
pages/home/home.vue

@ -256,7 +256,7 @@ export default {
// 3. openId // 3. openId
const openRes = await FetchOpenId({ const openRes = await FetchOpenId({
libcode: '1201',
libcode: config.LIB_CODE,
code: loginRes.code code: loginRes.code
}); });
@ -270,7 +270,7 @@ export default {
// 4. openId // 4. openId
const res = await FetchFindAllReaderBindByOpenId({ const res = await FetchFindAllReaderBindByOpenId({
libcode: '1201',
libcode: config.LIB_CODE,
openId: openId openId: openId
}); });
@ -305,7 +305,7 @@ export default {
// + base64 // + base64
async getRecommendBooks() { async getRecommendBooks() {
try { try {
const res = await FetchInitScreenBookRecommend({ libcode: '1201' });
const res = await FetchInitScreenBookRecommend({ libcode: config.LIB_CODE });
let books = res.data || []; let books = res.data || [];
// 3setData // 3setData
@ -441,7 +441,6 @@ export default {
this.$refs.popup.open(); this.$refs.popup.open();
}, },
closePopup() { closePopup() {
console.log('关闭弹窗');
this.qrcodeText = ''; this.qrcodeText = '';
this.$refs.popup.close(); this.$refs.popup.close();
}, },

7
pages/lendCar/lendCar.vue

@ -63,6 +63,7 @@
import { FetchInitScreenSetting } from '@/api/user'; import { FetchInitScreenSetting } from '@/api/user';
import { FetchRdloanlist, FetchRenewbook } from '@/api/book'; import { FetchRdloanlist, FetchRenewbook } from '@/api/book';
import { getCurrentReaderCard } from '@/utils/storage'; import { getCurrentReaderCard } from '@/utils/storage';
import config from '@/utils/config';
export default { export default {
data() { data() {
@ -111,7 +112,7 @@ export default {
try { try {
// 1. // 1.
await this.fetchScreenConfig();
await this.getScreenSetting();
// 2. // 2.
const currentReaderCard = await getCurrentReaderCard(); const currentReaderCard = await getCurrentReaderCard();
@ -136,8 +137,8 @@ export default {
/** /**
* 获取屏幕配置 * 获取屏幕配置
*/ */
async fetchScreenConfig() {
const res = await FetchInitScreenSetting({ libcode: '1201' });
async getScreenSetting() {
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
this.screenConfig = { this.screenConfig = {
thirdUrl: res.data.open_lib_http?.context || '', thirdUrl: res.data.open_lib_http?.context || '',
thirdAppid: res.data.open_lib_appId?.context || '', thirdAppid: res.data.open_lib_appId?.context || '',

20
pages/login/login.vue

@ -75,7 +75,7 @@ export default {
methods: { methods: {
// + // +
onChooseAvatar(e) { onChooseAvatar(e) {
console.log('获取微信头像', e)
// console.log('', e)
// //
const tempFilePath = e.detail.avatarUrl; const tempFilePath = e.detail.avatarUrl;
@ -88,24 +88,24 @@ export default {
"Content-Type": "multipart/form-data" "Content-Type": "multipart/form-data"
}, },
success: (res) => { success: (res) => {
console.log("上传成功原始返回:", res);
// console.log("", res);
let realAvatar = ''; let realAvatar = '';
try { try {
const data = JSON.parse(res.data); const data = JSON.parse(res.data);
console.log('解析成功:', data)
// console.log('', data)
realAvatar = data.data || data.url || ''; realAvatar = data.data || data.url || '';
} catch (e) { } catch (e) {
realAvatar = res.data; realAvatar = res.data;
} }
if (realAvatar) { if (realAvatar) {
console.log("永久头像URL:", realAvatar);
// console.log("URL", realAvatar);
this.avatarUrl = config.baseUrl + '/api/fileRelevant/getImg?imgType=5&imgId=' + realAvatar this.avatarUrl = config.baseUrl + '/api/fileRelevant/getImg?imgType=5&imgId=' + realAvatar
} else { } else {
uni.showToast({ title: '头像上传失败', icon: 'none' }); uni.showToast({ title: '头像上传失败', icon: 'none' });
} }
}, },
fail: (err) => { fail: (err) => {
console.log("上传失败", err);
// console.log("", err);
uni.showToast({ title: '头像上传失败', icon: 'none' }); uni.showToast({ title: '头像上传失败', icon: 'none' });
} }
}); });
@ -129,7 +129,7 @@ export default {
async getScreenSetting() { async getScreenSetting() {
try { try {
const res = await FetchInitScreenSetting({ libcode: '1201' });
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const data = res.data; const data = res.data;
this.screenConfig = { this.screenConfig = {
thirdUrl: data.open_lib_http?.context || '', thirdUrl: data.open_lib_http?.context || '',
@ -200,11 +200,11 @@ export default {
openid: openId, openid: openId,
bindValue: this.queryvalue, bindValue: this.queryvalue,
bindType: 'rdid', bindType: 'rdid',
libcode: '1201',
libcode: config.LIB_CODE,
} }
// //
const bindRes = await FetchBindReadCard(bindParams); const bindRes = await FetchBindReadCard(bindParams);
console.log('绑定结果', bindRes);
// console.log('', bindRes);
if(bindRes.code === 200 ){ if(bindRes.code === 200 ){
@ -214,11 +214,11 @@ export default {
icon: 'success' icon: 'success'
}); });
const data = { const data = {
libcode: '1201',
libcode: config.LIB_CODE,
openId: openId openId: openId
} }
FetchFindAllReaderBindByOpenId(data).then(res => { FetchFindAllReaderBindByOpenId(data).then(res => {
console.log('获取读者证列表',res)
// console.log('',res)
if (res.code === 200 && res.data.length > 0) { if (res.code === 200 && res.data.length > 0) {
uni.setStorageSync(STORAGE_KEYS.READER_CARD_LIST, res.data); uni.setStorageSync(STORAGE_KEYS.READER_CARD_LIST, res.data);
} else { } else {

5
pages/search/search.vue

@ -78,6 +78,7 @@
import { FetchInitScreenSetting } from '@/api/user'; import { FetchInitScreenSetting } from '@/api/user';
import { FetchBookSearch } from '@/api/book'; import { FetchBookSearch } from '@/api/book';
import BookListItem from "@/components/book-list-item/book-list-item.vue"; import BookListItem from "@/components/book-list-item/book-list-item.vue";
import config from '@/utils/config';
export default { export default {
components: { BookListItem }, components: { BookListItem },
@ -135,7 +136,7 @@ export default {
// opacUrl // opacUrl
async getOpacUrl() { async getOpacUrl() {
try { try {
const res = await FetchInitScreenSetting({ libcode: '1201' });
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
this.opacUrl = res.data.opac_url?.context || ''; this.opacUrl = res.data.opac_url?.context || '';
} catch (err) { } catch (err) {
console.error('获取配置失败', err); console.error('获取配置失败', err);
@ -174,7 +175,7 @@ export default {
}; };
const res = await FetchBookSearch(params); const res = await FetchBookSearch(params);
console.log('res',res)
// console.log('res',res)
// //
const apiData = res.data || {}; const apiData = res.data || {};

6
pages/user/user.vue

@ -82,9 +82,9 @@ export default {
if (openId) { if (openId) {
const res = await FetchFindAllReaderByOpenId({ const res = await FetchFindAllReaderByOpenId({
libcode: '1201',
openId: openId
});
libcode: config.LIB_CODE,
openId: openId
});
if (res.code === 200 && res.data) { if (res.code === 200 && res.data) {
this.userInfo = { this.userInfo = {

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

@ -153,7 +153,7 @@ export default {
// //
async getOpacUrl() { async getOpacUrl() {
try { try {
const res = await FetchInitScreenSetting({ libcode: '1201' });
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
this.opacUrl = res.data.opac_url?.context || ''; this.opacUrl = res.data.opac_url?.context || '';
this.getBookDetail(); this.getBookDetail();
} catch (err) {} } catch (err) {}
@ -170,17 +170,17 @@ export default {
bookrecno: this.bookrecno bookrecno: this.bookrecno
}; };
const res = await FetchFindbookByQuery(params); const res = await FetchFindbookByQuery(params);
console.log('bookrecno详情',res);
// console.log('bookrecno',res);
const apiData = res.data || {}; const apiData = res.data || {};
this.bookInfo = apiData.biblios || {}; this.bookInfo = apiData.biblios || {};
console.log('bookrecno-bookInfo详情',this.bookInfo);
// console.log('bookrecno-bookInfo',this.bookInfo);
this.holdingsData = apiData.holdings || []; this.holdingsData = apiData.holdings || [];
console.log('bookrecno-holdingsData详情',this.holdingsData);
// console.log('bookrecno-holdingsData',this.holdingsData);
this.checkCollectStatus(); this.checkCollectStatus();
} catch (err) { } catch (err) {
console.log(err);
console.error(err);
} finally { } finally {
uni.hideLoading(); uni.hideLoading();
} }

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

@ -76,7 +76,7 @@ export default {
async getBookRecommendList() { async getBookRecommendList() {
this.loading = true; this.loading = true;
try { try {
const res = await FetchInitScreenBookRecommend({ libcode: '1201' });
const res = await FetchInitScreenBookRecommend({ libcode: config.LIB_CODE });
let books = res.data || []; let books = res.data || [];
// 1. // 1.

2
subpkg/pages/feedback/feedback.vue

@ -82,7 +82,7 @@ export default {
this.formData.readerCard = readerCard.bindValue || ''; this.formData.readerCard = readerCard.bindValue || '';
} }
} catch (err) { } catch (err) {
console.error('Failed to load reader card info:', err);
console.error('获取读者证信息失败:', err);
} }
}, },

3
subpkg/pages/myLending/myLending.vue

@ -71,6 +71,7 @@ import { FetchHistoryloan, FetchRdloanlist, FetchCoverByISBN } from '@/api/book'
import myTabs from "@/components/my-tabs/my-tabs.vue"; import myTabs from "@/components/my-tabs/my-tabs.vue";
import lendingListItem from "@/components/lending-list-item/lending-list-item.vue"; import lendingListItem from "@/components/lending-list-item/lending-list-item.vue";
import { getCurrentReaderCard } from '@/utils/storage'; import { getCurrentReaderCard } from '@/utils/storage';
import config from '@/utils/config';
export default { export default {
components: { myTabs, lendingListItem }, components: { myTabs, lendingListItem },
@ -149,7 +150,7 @@ export default {
async getScreenSetting() { async getScreenSetting() {
try { try {
const res = await FetchInitScreenSetting({ libcode: '1201' });
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
const data = res.data; const data = res.data;
this.screenConfig = { this.screenConfig = {
thirdUrl: data.open_lib_http?.context || '', thirdUrl: data.open_lib_http?.context || '',

15
subpkg/pages/ranking/ranking.vue

@ -71,6 +71,7 @@
<script> <script>
import { FetchInitScreenSetting } from '@/api/user'; import { FetchInitScreenSetting } from '@/api/user';
import { FetchBookRanking } from '@/api/book'; import { FetchBookRanking } from '@/api/book';
import config from '@/utils/config';
export default { export default {
data() { data() {
@ -81,16 +82,16 @@ export default {
}, },
onLoad() { onLoad() {
this.getScreenConfig();
this.getScreenSetting();
}, },
methods: { methods: {
async getScreenConfig() {
async getScreenSetting() {
try { try {
const res = await FetchInitScreenSetting({ libcode: '1201' });
const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
this.getReadRanking(res.data); this.getReadRanking(res.data);
} catch (err) { } catch (err) {
console.log(err)
console.error('获取屏幕配置失败:', err);
} }
}, },
@ -110,7 +111,7 @@ export default {
const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}` const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
const params = { const params = {
'libcode': '1201',
'libcode': config.LIB_CODE,
'starttime': formattedDate, 'starttime': formattedDate,
'endtime': this.getFormattedDate(new Date()), 'endtime': this.getFormattedDate(new Date()),
'rownum': 10, 'rownum': 10,
@ -120,10 +121,10 @@ export default {
} }
FetchBookRanking(params).then(res => { FetchBookRanking(params).then(res => {
console.log('排行接口返回数据', res)
// console.log('', res)
const innerStr = res.data; const innerStr = res.data;
const resultJson = JSON.parse(innerStr); const resultJson = JSON.parse(innerStr);
console.log(resultJson)
// console.log(resultJson)
if (resultJson.success && resultJson.resultlist.length > 0) { if (resultJson.success && resultJson.resultlist.length > 0) {
// //

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

@ -73,6 +73,7 @@ import {
FetchUnbindReadCard FetchUnbindReadCard
} from '@/api/user'; } from '@/api/user';
import { getReaderCardList, getOpenId, setCurrentReaderCard, clearReaderCardCache, STORAGE_KEYS } from '@/utils/storage'; import { getReaderCardList, getOpenId, setCurrentReaderCard, clearReaderCardCache, STORAGE_KEYS } from '@/utils/storage';
import config from '@/utils/config';
export default { export default {
data() { data() {
@ -116,7 +117,7 @@ export default {
const readerList = await getReaderCardList(forceRefresh); const readerList = await getReaderCardList(forceRefresh);
this.cardList = readerList; this.cardList = readerList;
} catch (err) { } catch (err) {
console.error('[ReaderCard] Failed to load reader card list:', err);
console.error(err);
const cachedList = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || []; const cachedList = uni.getStorageSync(STORAGE_KEYS.READER_CARD_LIST) || [];
this.cardList = cachedList; this.cardList = cachedList;
} finally { } finally {
@ -145,21 +146,21 @@ export default {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '确定设为默认读者证吗?',
content: `确定设置【${value}】为默认读者证吗?`,
success: async (res) => { success: async (res) => {
if (!res.confirm) return; if (!res.confirm) return;
try { try {
await FetchSetDefaultReadCard({ await FetchSetDefaultReadCard({
bindType: 'rdid', bindType: 'rdid',
bindValue: value, bindValue: value,
libcode: '1201',
libcode: config.LIB_CODE,
openid: openId openid: openId
}); });
setCurrentReaderCard(value); setCurrentReaderCard(value);
await this.getBindReaderCardList(true); await this.getBindReaderCardList(true);
uni.showToast({ title: '设置成功', icon: 'success' }); uni.showToast({ title: '设置成功', icon: 'success' });
} catch (err) { } catch (err) {
console.error('[ReaderCard] Failed to set default card:', err);
console.error(err);
uni.showToast({ title: '设置失败', icon: 'none' }); uni.showToast({ title: '设置失败', icon: 'none' });
} }
} }
@ -172,7 +173,6 @@ export default {
}, },
closePopup() { closePopup() {
console.log('关闭弹窗');
this.qrcodeText = ''; this.qrcodeText = '';
this.$refs.popup.close(); this.$refs.popup.close();
}, },
@ -202,7 +202,7 @@ export default {
const result = await FetchUnbindReadCard({ const result = await FetchUnbindReadCard({
bindType: "rdid", bindType: "rdid",
bindValue: this.selectedValue, bindValue: this.selectedValue,
libcode: "1201",
libcode: config.LIB_CODE,
openid: openId openid: openId
}); });
@ -216,7 +216,7 @@ export default {
await FetchSetDefaultReadCard({ await FetchSetDefaultReadCard({
bindType: 'rdid', bindType: 'rdid',
bindValue: newValue, bindValue: newValue,
libcode: '1201',
libcode: config.LIB_CODE,
openid: openId openid: openId
}); });
setCurrentReaderCard(newValue); setCurrentReaderCard(newValue);
@ -229,7 +229,7 @@ export default {
} }
} }
} catch (err) { } catch (err) {
console.error('[ReaderCard] Failed to unbind card:', err);
console.error(err);
uni.showToast({ title: '解绑失败', icon: 'none' }); uni.showToast({ title: '解绑失败', icon: 'none' });
} }
} }

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

@ -140,7 +140,7 @@ export default {
const openId = uni.getStorageSync('wx_login_code') || ''; const openId = uni.getStorageSync('wx_login_code') || '';
const params = { const params = {
avatar: this.imgId, avatar: this.imgId,
libcode: "1201",
libcode: config.LIB_CODE,
nickname: this.nickname, nickname: this.nickname,
openid: openId openid: openId
}; };

9
utils/config.js

@ -9,6 +9,11 @@ const CONFIG = {
// assetsPath: 'https://m.siccat.com/public/static/images/', // 静态资源路径 // assetsPath: 'https://m.siccat.com/public/static/images/', // 静态资源路径
baseUrl: 'http://192.168.99.63:14000', // 后台接口请求地址 baseUrl: 'http://192.168.99.63:14000', // 后台接口请求地址
} }
}; };
export default CONFIG[process.env.NODE_ENV];
const config = CONFIG[process.env.NODE_ENV];
// 图书馆代码常量
config.LIB_CODE = '1201';
export default config;

12
utils/index.js

@ -1,12 +0,0 @@
/**
* 返回随机色值
*/
export let getRandomColor = () => {
const rgb = [];
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16);
color = color.length == 1 ? '0' + color : color;
rgb.push(color);
}
return '#' + rgb.join('');
};

21
utils/storage.js

@ -3,6 +3,7 @@
* 提供缓存降级策略先从缓存获取缓存不存在则调用接口重新获取 * 提供缓存降级策略先从缓存获取缓存不存在则调用接口重新获取
*/ */
import { FetchOpenId, FetchFindAllReaderBindByOpenId } from '@/api/user'; import { FetchOpenId, FetchFindAllReaderBindByOpenId } from '@/api/user';
import config from '@/utils/config';
// 缓存键名常量 // 缓存键名常量
export const STORAGE_KEYS = { export const STORAGE_KEYS = {
@ -35,18 +36,18 @@ export async function getOpenId() {
}); });
if (!loginRes.code) { if (!loginRes.code) {
console.warn('[Storage] WeChat login failed');
console.warn('[Storage] 获取code失败');
return null; return null;
} }
// 4. 获取 openId // 4. 获取 openId
const openRes = await FetchOpenId({ const openRes = await FetchOpenId({
libcode: '1201',
libcode: config.LIB_CODE,
code: loginRes.code code: loginRes.code
}); });
if (openRes.code !== 200 || !openRes.data) { if (openRes.code !== 200 || !openRes.data) {
console.warn('[Storage] Failed to fetch openId');
console.warn('[Storage] 获取openId失败');
return null; return null;
} }
@ -55,7 +56,7 @@ export async function getOpenId() {
return openId; return openId;
} catch (err) { } catch (err) {
console.error('[Storage] Error in getOpenId:', err);
console.error('[Storage] 获取openId失败:', err);
return null; return null;
} }
} }
@ -79,12 +80,12 @@ export async function getCurrentReaderCard() {
const openId = await getOpenId(); const openId = await getOpenId();
if (!openId) { if (!openId) {
console.warn('[Storage] No openId found, cannot fetch reader card');
console.warn('[Storage] 获取openId失败');
return null; return null;
} }
const res = await FetchFindAllReaderBindByOpenId({ const res = await FetchFindAllReaderBindByOpenId({
libcode: '1201',
libcode: config.LIB_CODE,
openId: openId openId: openId
}); });
@ -103,7 +104,7 @@ export async function getCurrentReaderCard() {
return resultCard; return resultCard;
} }
} catch (err) { } catch (err) {
console.error('[Storage] Failed to fetch reader card:', err);
console.error('[Storage] 获取读者证失败:', err);
} }
return null; return null;
@ -131,12 +132,12 @@ export async function getReaderCardList(forceRefresh = false) {
const openId = await getOpenId(); const openId = await getOpenId();
if (!openId) { if (!openId) {
console.warn('[Storage] No openId found, cannot fetch reader card list');
console.warn('[Storage] 获取openId失败');
return []; return [];
} }
const res = await FetchFindAllReaderBindByOpenId({ const res = await FetchFindAllReaderBindByOpenId({
libcode: '1201',
libcode: config.LIB_CODE,
openId: openId openId: openId
}); });
@ -158,7 +159,7 @@ export async function getReaderCardList(forceRefresh = false) {
return readerCardList; return readerCardList;
} }
} catch (err) { } catch (err) {
console.error('[Storage] Failed to fetch reader card list:', err);
console.error('[Storage] 获取读者证列表失败:', err);
} }
return []; return [];

Loading…
Cancel
Save