将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
125 lines
4.1 KiB
JavaScript
125 lines
4.1 KiB
JavaScript
var t = getApp(), e = require("../../utils/login.js");
|
|
|
|
Page({
|
|
data: {
|
|
showLoding: !0,
|
|
urlList: [],
|
|
user: {}
|
|
},
|
|
onLoad: function(n) {
|
|
var o = this;
|
|
e.pageStart(t).then(function(t) {
|
|
o.getContent();
|
|
});
|
|
},
|
|
onShow: function() {
|
|
this.refresh && this.getContent();
|
|
},
|
|
onPullDownRefresh: function() {},
|
|
onShareAppMessage: function() {},
|
|
getContent: function() {
|
|
var n = this;
|
|
wx.showLoading({
|
|
title: ""
|
|
}), e.request('/miniprogram/user', {}, !0).then(function(t) {
|
|
if (wx.hideLoading(), 200 != t.code) return wx.showModal({
|
|
title: "提示",
|
|
content: t.message
|
|
}), !1;
|
|
n.setData({
|
|
showLoding: !1,
|
|
user: t.data.user,
|
|
urlList: t.data.menu
|
|
}, function() {});
|
|
}).catch(function(t) {
|
|
wx.hideLoading();
|
|
});
|
|
},
|
|
islogin: function() {
|
|
wx.showLoading({
|
|
title: "加载中"
|
|
});
|
|
},
|
|
refresh: 0,
|
|
toPage: function(t) {
|
|
var e = t.currentTarget.dataset, n = (e.refresh, e.url);
|
|
n ? wx.navigateTo({
|
|
url: "/pages/".concat(n)
|
|
}) : wx.showToast({
|
|
title: "页面开发中~",
|
|
icon: "none",
|
|
duration: 2e3
|
|
}), this.refresh = 1;
|
|
},
|
|
callUs: function() {
|
|
if (!t.globalData.servicetel) return !1;
|
|
wx.makePhoneCall({
|
|
phoneNumber: "" + t.globalData.servicetel
|
|
});
|
|
},
|
|
updateUserAvatar: function() {
|
|
var that = this;
|
|
wx.chooseMedia({
|
|
count: 1,
|
|
mediaType: ['image'],
|
|
sourceType: ['album', 'camera'],
|
|
success: function(res) {
|
|
wx.uploadFile({
|
|
url: 'https://t-jm.v0750.com/miniprogram/upload',
|
|
filePath: res.tempFiles[0].tempFilePath,
|
|
name: 'file',
|
|
success: function(uploadRes) {
|
|
var data = JSON.parse(uploadRes.data);
|
|
if (data.code == 200) {
|
|
e.request('/miniprogram/user/update', {
|
|
avatar: data.data.url
|
|
}, true).then(function(res) {
|
|
if (res.code == 200) {
|
|
that.getContent();
|
|
wx.showToast({
|
|
title: '头像更新成功',
|
|
icon: 'success'
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
},
|
|
updateUserNickname: function() {
|
|
var that = this;
|
|
wx.showModal({
|
|
title: '修改昵称',
|
|
editable: true,
|
|
placeholderText: '请输入新昵称',
|
|
success: function(res) {
|
|
if (res.confirm && res.content) {
|
|
// 发送请求到后端,更新用户昵称
|
|
e.request('/miniprogram/user/update', {
|
|
nickname: res.content
|
|
}, true).then(function(res) {
|
|
if (res.code == 200) {
|
|
that.getContent();
|
|
wx.showToast({
|
|
title: '昵称更新成功',
|
|
icon: 'success'
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}); |