Browse Source

优化更新2

master
xuhuajiao 3 weeks ago
parent
commit
a7497aa928
  1. 101
      pages/login/login.vue
  2. 14
      utils/request.js

101
pages/login/login.vue

@ -153,19 +153,15 @@ export default {
console.error('获取配置失败:', err);
}
},
async submit() {
//
this.nickName = this.nickName.trim()
this.queryvalue = this.queryvalue.trim()
if (!this.queryvalue || !this.rdpasswd) {
uni.showToast({ title: '请输入读者证号和密码', icon: 'none' });
return;
}
uni.showLoading({ title: '绑定中...' });
try {
const params = {
...this.screenConfig,
@ -173,12 +169,6 @@ export default {
queryvalue: this.queryvalue,
rdpasswd: this.rdpasswd,
};
// 420703GD0000748
// {"code":200,"message":"","data":"{\"messagelist\":[{\"code\":\"R00138\",\"message\":\"\"}],\"success\":false}","timestamp":1778154499544}
// {"code":200,"message":"","data":"{\"success\":true,\"pagedata\":[{\"rdClusterCode\":null,\"rdlib\":\"GD\",\"rdid\":\"420105198509200438\",\"rdcfstate\":1}]}","timestamp":1778154647854}
// {"code":200,"message":"","data":"{\"messageList\":[{\"R00131\":\"\"}],\"success\":true,\"pagedata\":\"\"}","timestamp":1778155520501}
const res = await FetchReaderList(params);
let result = {};
@ -189,7 +179,6 @@ export default {
uni.showToast({ title: '数据解析失败', icon: 'none' });
return;
}
//
let errMsg = '';
if (result.messagelist?.length) {
@ -201,35 +190,50 @@ export default {
errMsg = item.message || Object.values(item)[0] || '认证失败';
}
// 420703GD0000748
// {"code":200,"message":"","data":"{\"messagelist\":[{\"code\":\"R00138\",\"message\":\"\"}],\"success\":false}","timestamp":1778154499544}
// {"code":200,"message":"","data":"{\"success\":true,\"pagedata\":[{\"rdClusterCode\":null,\"rdlib\":\"GD\",\"rdid\":\"420105198509200438\",\"rdcfstate\":1}]}","timestamp":1778154647854}
// {"code":200,"message":"","data":"{\"messageList\":[{\"R00131\":\"\"}],\"success\":true,\"pagedata\":\"\"}","timestamp":1778155520501}
//
const realSuccess = result.success === true && result.pagedata?.length > 0;
if (realSuccess) {
//
const openId = uni.getStorageSync("wx_login_code");
if (!openId) {
uni.hideLoading();
uni.showModal({
title: '绑定提示',
content: '未获取到微信登录信息,请重新登录',
showCancel: false
})
return;
}
const bindParams = {
openid: openId,
bindValue: this.queryvalue,
bindType: 'rdid',
libcode: getApp().globalData.libcode,
}
//
const bindRes = await FetchBindReadCard(bindParams);
console.log('绑定结果', bindRes);
if(bindRes.code === 200 ){
// ========== trycatchcatch ==========
try {
const bindRes = await FetchBindReadCard(bindParams);
if (bindRes.code === 200) {
uni.hideLoading();
uni.showToast({
title: bindRes.data || '读者证绑定成功',
icon: 'success'
});
uni.showModal({
title: '绑定成功',
content: bindRes.data || '读者证绑定成功',
showCancel: false,
success: (modalRes) => {
if (modalRes.confirm) {
const data = {
libcode: getApp().globalData.libcode,
openId: openId
}
FetchFindAllReaderBindByOpenId(data).then(res => {
// console.log('',res)
if (res.code === 200 && res.data.length > 0) {
uni.setStorageSync(STORAGE_KEYS.READER_CARD_LIST, res.data);
} else {
@ -239,32 +243,59 @@ export default {
.catch(err => {
console.error('获取读者证列表失败:', err);
})
//
setTimeout(() => {
uni.navigateBack();
}, 1500);
}else{
//
}
}
});
} else {
//
uni.hideLoading()
uni.showToast({
title: bindResult.message || '绑定失败,请重试',
icon: 'none'
const failMsg = bindRes.message || '绑定失败,请重试';
uni.showModal({
title: '绑定失败',
content: failMsg,
showCancel: false
})
}
} catch (bindErr) {
// http
uni.hideLoading();
let errTip = typeof bindErr === 'string' ? bindErr : '绑定请求异常,请稍后重试';
uni.showModal({
title: '系统异常',
content: errTip,
showCancel: false
});
}
// ======================================================================
} else {
uni.hideLoading();
uni.showToast({
title: errMsg || '读者证或密码错误',
icon: 'none'
uni.showModal({
title: '认证失败',
content: errMsg || '读者证或密码错误',
showCancel: false
});
}
} catch (err) {
console.error('绑定流程异常:', err)
uni.hideLoading();
uni.showToast({ title: err || '绑定失败', icon: 'none' });
let errTip = ''
if (typeof err === 'string') {
errTip = err
} else if (err && err.message) {
errTip = err.message
} else {
errTip = '绑定失败,请稍后重试'
}
uni.showModal({
title: '系统异常',
content: errTip,
showCancel: false
});
}
},
/**
* 跳转到在线办证页面
*/

14
utils/request.js

@ -27,10 +27,8 @@ function request({ url, data, method = 'GET' }) {
if (store.state.user.token) {
header.Authorization = store.state.user.token;
}
let finalUrl = BASE_URL + url
let finalData = data
// GET 请求:手动拼装query,数组展开多同名参数
if (method.toUpperCase() === 'GET' && data && typeof data === 'object') {
const query = buildQuery(data)
@ -39,24 +37,14 @@ function request({ url, data, method = 'GET' }) {
}
finalData = undefined // GET 清空data,防止uni.request重复处理
}
uni.request({
url: finalUrl,
data: finalData,
method: method.toUpperCase(),
header,
success: ({ data }) => {
if (data.code === 200) {
// ✅ 全部直接resolve,业务层自己判断code,不再reject业务错误
resolve(data);
} else {
uni.showToast({
title: data.message || '请求失败',
icon: 'none',
mask: true,
duration: 3000
});
reject(data.message);
}
},
fail: (error) => {
uni.showToast({

Loading…
Cancel
Save