This commit is contained in:
@zuopngfei 2025-10-21 16:58:18 +08:00
parent 04f5606d22
commit 86b605b574
2 changed files with 11 additions and 10 deletions

View File

@ -1,5 +1,5 @@
const baseUrl = 'https://mini-chat.1024tool.vip/';
// const baseUrl = 'https://mini-chat.1024tool.vip/api/';
const baseUrl = 'https://dsjhd9s.tbmw.cn/api/'
function request(url, method = 'GET', data = {}) {
const header = {

View File

@ -64,25 +64,26 @@ Page({
getMessages() {
const userInfo = wx.getStorageSync('user_info');
const that = this;
request('app/messages', 'get', {
app_id: this.data.appid,
app_id: that.data.appid,
user_id: userInfo.openid,
page: this.data.page,
page_size: this.data.page_size,
page: that.data.page,
page_size: that.data.page_size,
}).then(res => {
console.log('res', res);
// generate stable ids across pages so we can prepend without collisions
const base = (this.data.page - 1) * this.data.page_size;
const base = (that.data.page - 1) * that.data.page_size;
const list = res.list.map((item, index) => {
item.id = 'm' + (base + index);
item.content = JSON.parse(item.content);
return item;
});
this.setData({
that.setData({
messages: list,
total: res.total,
// only auto-scroll if user is at bottom
scrollToId: this.data.isAtBottom ? (list[list.length - 1] ? list[list.length - 1].id : '') : this.data.scrollToId
scrollToId: that.data.isAtBottom ? (list[list.length - 1] ? list[list.length - 1].id : '') : that.data.scrollToId
});
console.log('messages', list);
})
@ -146,7 +147,7 @@ Page({
const accountInfo = wx.getAccountInfoSync();
wx.login({
success: function (res) {
request('api/wechat/miniprogram/login', 'post', {
request('wechat/miniprogram/login', 'post', {
"app_id": accountInfo.miniProgram.appId,
"js_code": res.code,
"encrypted_data": user.encryptedData,
@ -156,7 +157,7 @@ Page({
}).then(resp => {
wx.setStorageSync('user_info', resp);
// wx.setStorageSync('open_id', resp.openid);
this.setData({
that.setData({
showGetUser: false,
userInfo: resp
});