xz_mini/pages/commonQrCode/commonQrCode.js

98 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-07-27 14:28:57 +08:00
// subpages/commonQrCode.js
const app = getApp();
var socket = null;
Page({
/**
* 页面的初始数据
*/
data: {
title: '日喀则市公共数字文化云',
desc: '开展新闻资讯、场馆导航、场馆预定、活动预约、艺术普及、在线培训、电子图书、文化点单、直播活动等。',
hint: '扫描或长按识别上面二维码进行关注公众号',
imgSrc: '',
userId: '',
urls: app.wssUrl,
userName: '码',
hideloading: false,
},
onLoad(options) {
console.log(options)
wx.setNavigationBarTitle({
title: '公众号关注',
});
wx.setNavigationBarColor({
backgroundColor: '#ededed',
frontColor: '#000000',
})
var userId = "";
if (options && JSON.stringify(options) !== '{}') {
var keys = Object.keys(options)
var values = keys[0].split("=");
userId = values[1];
this.setData({
userId: userId
})
} else {
userId = app.globalData.userInfo.userId;
this.setData({
userId: userId
})
this.startWebSocket();
}
this.getCodeImg(userId);
},
startWebSocket() {
var _self = this;
socket = wx.connectSocket({
url: _self.data.urls + '/app/wxeventrelease/' + _self.data.userId,
success(res) {
console.log(res)
}
});
socket.onMessage(function (e) {
console.log(e)
if (e.data) {
var data = JSON.parse(e.data);
_self.prePage(data.attention)
}
});
},
prePage(e) {
console.log(e)
app.globalData.isPublic = e
var pages = getCurrentPages();
var prePage = pages[pages.length - 2]
prePage.setData({
isPublic: e
});
wx.navigateBack()
},
onUnload() {
if (socket != null) {
socket.close({
code: 1000
});
}
},
getCodeImg(id) {
var _self = this;
app.restAjax.get(app.restAjax.path('{usercenterUrl}/app/wxopen/qrcoderelease/{userId}', [app.usercenterUrl, id]), {}, {
}, function (code, data) {
_self.setData({
imgSrc: data,
hideloading: true
})
}, function (code, data) {
_self.setData({
hideloading: true
})
app.dialog.msg(data.msg);
})
},
onShow() {
},
})