| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
- // pages/mine/mine.js
- import {getCheckInInfo, getDrawImg} from "./getPosterObj";
- const defaultAvatarUrl = "../../static/images/no-login.png"
- const homeApi_empower = "https://aipush.aidsleep.cn";
- import api from '../../utils/api';
- Page({
- imagePath: '',
- history: [],
- future: [],
- isSave: false,
- /**
- * 页面的初始数据
- */
- data: {
- showAuthorizedDialog: false,
- showTipsA: false,
- showTipsB: false,
- show1:false,
- aid:null,
- hasAuth: false,
- seeAicoList: "/subpagesTwo/seeAisoList/seeAicoList",
- avatarUrl: defaultAvatarUrl,
- nickName: "用户登录",
- phoneNumber: "",
- latitude: null,
- longitude: null,
- menuCardList: [],
- customActionStyle: {
- border: {
- borderColor: '#1A7AF8',
- },
- scale: {
- textIcon: '/palette/switch.png',
- imageIcon: '/palette/scale.png',
- },
- delete: {
- icon: '/palette/close.png',
- },
- },
- paintPallette: {},
- template: {},
- showImg:false
- },
- onClickShow() {
- this.setData({ showImg: true });
- },
- onClickHide() {
- this.setData({ showImg: false });
- },
- handleSureDownload() {
- this.isSave = false;
- api.painter({
- params: {score: 69},
- }).then(data => {
- if (data.code === 1) {
- var DrawImg = getDrawImg(data?.data?.pic||'/static/painter/hua.png', 0);
- var CheckInInfo = getCheckInInfo(data?.data?.talk|| "亲爱的,哪怕只有一分钟的平静闭眼,也是身体在努力修复的信号。新的一天,新的开始!", DrawImg.height);
- // 定义 palette 对象
- const palette = {
- "width": "750rpx",
- "height": CheckInInfo.height + "rpx",
- "background": "transparent",
- "views": [
- ...DrawImg.obj,
- ...CheckInInfo.obj,
- ]
- };
- // 更新数据到页面
- this.isSave = true;
- this.setData({
- paintPallette: palette
- });
- } else {
- }
- }).catch(err => {
- });
- },
- saveImage() {
- console.log("saveImage", this.imagePath)
- if (this.imagePath && typeof this.imagePath === 'string') {
- this.isSave = false;
- // 存入系统相册
- wx.saveImageToPhotosAlbum({
- filePath: this.imagePath || '',
- success: res => {
- this.onClickHide()
- },
- fail: res => {
- this.onClickHide()
- }
- })
- }
- },
- // 生成海报点击事件
- onImgOK(e) {
- this.imagePath = e.detail.path;
- this.setData({
- image: this.imagePath,
- });
- if (this.isSave) {
- this.onClickShow()
- }
- },
- touchEnd({detail}) {
- let needRefresh = detail.index >= 0 && detail.index <= this.data.template.views.length;
- if (needRefresh) {
- this.history.push({
- ...detail,
- });
- if (this.data.template.views[detail.index].id === detail.view.id) {
- this.data.template.views.splice(detail.index, 1);
- } else {
- this.data.template.views.splice(detail.index, 0, detail.view);
- }
- } else {
- if (!this.data.template || !this.data.template.views) {
- return;
- }
- for (let view of this.data.template.views) {
- if (view.id === detail.view.id) {
- this.history.push({
- view: {
- ...detail.view,
- ...view,
- },
- });
- view.css = detail.view.css;
- break;
- }
- }
- }
- this.future.length = 0;
- const props = {
- paintPallette: this.data.template,
- };
- if (needRefresh) {
- props.template = this.data.template;
- }
- this.setData(props);
- },
- getLocation() {
- const that = this;
- var hasAuth = wx.getStorageSync("hasAuth");
- if (!hasAuth) {
- return
- }
- wx.getSetting({
- success(res) {
- if (res.authSetting['scope.userLocation']) {
- // 用户已经授权
- wx.getLocation({
- type: 'gcj02', // 返回可以用于wx.openLocation的经纬度
- success(locationRes) {
- that.setData({
- latitude: locationRes.latitude,
- longitude: locationRes.longitude,
- });
- console.log('纬度:', locationRes.latitude);
- console.log('经度:', locationRes.longitude);
- that.savehotelnew();
- },
- fail(err) {
- that.setData({
- latitude: null,
- longitude: null,
- error: err.message
- });
- console.error('获取位置失败:', err.message);
- }
- });
- } else {
- // 用户未授权
- // wx.authorize({
- // scope: 'scope.userLocation',
- // success() {
- // // 用户同意授权后再次获取位置
- // that.savehotelnew();
- // },
- // fail() {
- // // 用户拒绝授权
- // that.setData({
- // latitude: null,
- // longitude: null,
- // error: '用户拒绝授权获取地理位置'
- // });
- // console.error('用户拒绝授权获取地理位置');
- // }
- // });
- }
- }
- });
- },
- savehotelnew() {
- const that = this;
- console.log({
- token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
- unionid: wx.getStorageSync('unionid'),
- longandlat: that.data.longitude + "|" + that.data.latitude
- });
-
- wx.request({
- url: 'https://aipush.aidsleep.cn/savehotelnew',
- method: 'POST',
- data: {
- token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
- unionid: wx.getStorageSync('unionid'),
- longandlat: that.data.longitude + "|" + that.data.latitude
- },
- success: (res) => {
- },
- fail: () => {
- }
- });
- },
- onCloseTipsDialog() {
- this.setData({
- showTipsA: false,
- showTipsB: false
- })
- },
- onMenuClick(e) {
- console.log(e.currentTarget.dataset);
- const { index } = e.currentTarget.dataset;
- var hasAuth = wx.getStorageSync("hasAuth");
- switch (index - 0) {
- case 0:
- // need Login
- if (hasAuth) {
- this.toPage(index);
- } else {
- this.showDialog();
- }
- break;
- default:
- this.toPage(index);
- break;
- }
- },
- bindAccount(){
- // 调用 /data/api.data/bind
- api.bind({
- params: { aid: this.data.aid ||10011},
- headers: { unionid: wx.getStorageSync("unionid")},
- })
- .then(data =>{
- if (data.code === 1) {
- wx.showToast({
- icon: 'none',
- title: data.info,
- });
- }else{
- wx.showToast({
- icon: 'none',
- title: data.info,
- });
- }
- this.isManager()
- })
- .catch(err => console.error('Bind Error:', err));
- },
- isManager(){
- // 调用 /data/api.data/isManager
- api.isManager({
- params: {},
- headers: { unionid: wx.getStorageSync("unionid")},
- })
- .then(data =>{
- if (data.code === 1) {
- wx.setStorageSync('isManager', data.data);
- }else{
- wx.setStorageSync('isManager', null);
- }
- this.initMenuCardList()
- })
- .catch(err => console.error('IsManager Error:', err));
- },
- toPage(index) {
- const type = this.data.menuList[index].type;
- const url = this.data.menuList[index].url;
- if (!url) {
- this.handleSureDownload()
- return
- }
- if (type == 'switchTab') {
- wx.switchTab({
- url: url
- })
- } else if (type == 'navigate') {
- wx.navigateTo({
- url: url
- })
- } else if (type == 'miniProgram') {
- //develop开发版;trial体验版;release正式版
- const appId = this.data.menuCardList[index].appId;
- wx.navigateToMiniProgram({
- appId: appId,
- path: url,
- extraData: {
- },
- envVersion: 'develop',
- success(res) {
- // 打开成功
- }
- })
- }
- },
- onMenuCardClick(e) {
- console.log(e.currentTarget.dataset);
- const { index } = e.currentTarget.dataset;
- var hasAuth = wx.getStorageSync("hasAuth");
- switch (index - 0) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- // need Login
- if (hasAuth) {
- if (index == 0) {
- let that=this
- // 判断扫码控制权限
- wx.request({
- url: `${homeApi_empower}/wxstatus`,
- data: {
- unionid: wx.getStorageSync('unionid'),
- openid: wx.getStorageSync('openid'),
- token: wx.getStorageSync('token'),
- },
- method: 'POST',
- success: function (intervalRes) {
- //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
- if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
- wx.setStorageSync('hasHotelAuth', true);
- wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
- wx.setStorageSync('roomEmpower', intervalRes.data.room);
- wx.setStorageSync('hname', intervalRes.data.hname);
- wx.setStorageSync('rname', intervalRes.data.rname);
- } else {
- wx.setStorageSync('hasHotelAuth', false);
- }
- var hasHotelAuth = wx.getStorageSync("hasHotelAuth");
- if (!hasHotelAuth) {
- that.setData({
- showTipsB: true
- })
- return
- }
- that.toCardPage(index);
- },
- fail: function (error) {
- }
- });
- return;
- }
- if (index == 2) {
- var hasReportAuth = wx.getStorageSync("hasReportAuth");
- var unionid = wx.getStorageSync("unionid");
- if (!unionid) {
- this.setData({
- showTipsA: true
- })
- return
- }
- if (!hasReportAuth) {
- wx.showModal({
- title: '提示',
- content: '没有睡眠报告',
- showCancel: false
- });
- return
- }
- }
- this.toCardPage(index);
- } else {
- this.showDialog();
- }
- break;
- default:
- this.toCardPage(index);
- break;
- }
- },
- toCardPage(index) {
- const type = this.data.menuCardList[index].type;
- const url = this.data.menuCardList[index].url;
- if (!url) {
- return
- }
- if (type == 'switchTab') {
- wx.switchTab({
- url: url
- })
- } else if (type == 'navigate') {
- wx.navigateTo({
- url: url
- })
- } else if (type == 'miniProgram') {
- //develop开发版;trial体验版;release正式版
- const appId = this.data.menuCardList[index].appId;
- wx.navigateToMiniProgram({
- appId: appId,
- path: url,
- extraData: {
- },
- envVersion: 'develop',
- success(res) {
- // 打开成功
- }
- })
- }
- },
- toSubscriptions() {
- const tmplIds = 'k7OQFUKk8elm3ca3EoIfMFe81u0DCIuDSk300a2obxw';
- // 这里是获取下发权限地方,根据官方文档,可以根据 wx.getSetting() 的 withSubscriptions 这个参数获取用户是否打开订阅消息总开关。后面我们需要获取用户是否同意总是同意消息推送。所以这里要给它设置为true 。
- wx.getSetting({
- withSubscriptions: true, // 这里设置为true,下面才会返回mainSwitch
- success: function (res) {
- // 调起授权界面弹窗
- if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
- if (res.subscriptionsSetting.itemSettings != null) { // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
- let moIdState = res.subscriptionsSetting.itemSettings[tmplIds]; // 用户同意的消息模板id
- if (moIdState === 'accept') {
- console.log('接受了消息推送');
- } else if (moIdState === 'reject') {
- console.log("拒绝消息推送");
- } else if (moIdState === 'ban') {
- console.log("已被后台封禁");
- }
- } else {
- // 当用户没有点击 ’总是保持以上选择,不再询问‘ 按钮。那每次执到这都会拉起授权弹窗
- wx.showModal({
- title: '提示',
- content: '请授权开通服务通知',
- showCancel: true,
- success: function (ress) {
- if (ress.confirm) {
- wx.requestSubscribeMessage({ // 调起消息订阅界面
- tmplIds: ['k7OQFUKk8elm3ca3EoIfMFe81u0DCIuDSk300a2obxw', 'JSM4TwUMy5w5AHvdmJv7_NQ0h5FstGqtc12fqPOoPQU','rO9DCTKcSCxEIVp6GsV56hCLPwFKhvVytXGRkJxtTO4'],
- success(res) {
- console.log('订阅消息 成功 ');
- console.log(res);
- },
- fail(er) {
- console.log("订阅消息 失败 ");
- console.log(er);
- }
- })
- }
- }
- })
- }
- } else {
- console.log('订阅消息未开启')
- }
- },
- fail: function (error) {
- console.log(error);
- },
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- wx.hideTabBar()
- if (options.aid){
- this.setData({
- aid:options.aid
- })
- }
- this.initMenuCardList()
- // this.toSubscriptions();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- wx.hideTabBar()
- this.getLocation();
- },
- bindAccountPopup() {
- this.bindAccount()
- this.setData({
- show1: false,
- aid:null
- });
- },
- onClose() {
- this.setData({
- show1: false,
- });
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- wx.hideTabBar()
- this.checkAuth()
- },
- showDialog() {
- var hasAuth = wx.getStorageSync("hasAuth");
- if (hasAuth) {
- return
- }
- this.setData({
- showAuthorizedDialog: true
- })
- },
- checkAuth() {
- var hasAuth = wx.getStorageSync("hasAuth");
- this.setData({
- hasAuth: hasAuth
- })
- if (hasAuth) {
- var userInfo = wx.getStorageSync("userInfo");
- this.setData({
- nickName: userInfo.nickName || "用户登录",
- avatarUrl: userInfo.avatarUrl || defaultAvatarUrl,
- phoneNumber: userInfo.phoneNumber || ""
- })
- this.initMenuCardList()
- var storageSync = wx.getStorageSync("unionid");
- if (storageSync &&this.data.aid) {
- this.setData({
- show1: true,
- })
- }
- // 判断扫码控制权限
- wx.request({
- url: `${homeApi_empower}/wxstatus`,
- data: {
- unionid: wx.getStorageSync('unionid'),
- openid: wx.getStorageSync('openid'),
- token: wx.getStorageSync('token'),
- },
- method: 'POST',
- success: function (intervalRes) {
- console.log('intervalRes=' + JSON.stringify(intervalRes));
- console.log('intervalRes.data=' + JSON.stringify(intervalRes.data));
- //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
- if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
- wx.setStorageSync('hasHotelAuth', true);
- wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
- wx.setStorageSync('roomEmpower', intervalRes.data.room);
- wx.setStorageSync('hname', intervalRes.data.hname);
- wx.setStorageSync('rname', intervalRes.data.rname);
- } else {
- wx.setStorageSync('hasHotelAuth', false);
- }
- },
- fail: function (error) {
- }
- });
- }
- return hasAuth;
- },
- initMenuCardList(){
- this.setData({menuCardList:[{
- icon: "../../static/index/icon/ic_fjkz.png",
- bgIcon: "../../static/index/bg/bg_fjkz.png",
- title: "房间控制",
- type: "navigate",
- color: "#3C84D9",
- bgColor: "#EEF4FF",
- url: "/subpages/main/main"
- }, {
- icon: "../../static/index/icon/ic_sm.png",
- bgIcon: "../../static/index/bg/bg_sm.png",
- title: "扫码",
- type: "navigate",
- color: "#10B09C",
- bgColor: "#E6FFFC",
- url: "/subpages/scan/scan"
- }, {
- icon: "../../static/index/icon/ic_jrsmbg.png",
- bgIcon: "../../static/index/bg/bg_jrsmbg.png",
- title: "最新睡眠报告",
- type: "navigate",
- color: "#8658B9",
- bgColor: "#F6F3FF",
- url: "/subpages/data/data"
- }, {
- icon: "../../static/index/icon/ic_lssmbg.png",
- bgIcon: "../../static/index/bg/bg_lssmbg.png",
- title: "历史睡眠报告",
- type: "navigate",
- color: "#BB6268",
- bgColor: "#FFF6F7",
- url: "/subpages/sleepReport/sleepReport"
- }, {
- icon: "../../static/index/icon/ic_wdcd.png",
- bgIcon: "../../static/index/bg/bg_wdcd.png",
- title: wx.getStorageSync("isManager")?"巡检房间" : "我的床垫",
- type: "navigate",
- color: "#317A9B",
- bgColor: "#E6FFFC",
- url: wx.getStorageSync("isManager")?this.data.seeAicoList+'?hotel_id='+wx.getStorageSync("isManager")[0] : "/subpages/myMattress/myMattress"
- }, {
- icon: "../../static/index/icon/ic_zxsc.png",
- bgIcon: "../../static/index/bg/bg_zxsc.png",
- title: "在线商城",
- type: "miniProgram",
- color: "#C2714B",
- bgColor: "#FFF8F4",
- appId: "wx63f79b3d61ba632b" || "gh_78da4ac5d0cc",
- url: "pages/home/dashboard/index"
- }],
- menuList: [{
- icon: "../../static/mine/dcwj.png",
- title: "健康检测",
- type: "navigate",
- url: "/subpages/testSAS/testSAS"
- }, {
- icon: "../../static/mine/zxkf.png",
- title: "在线客服",
- type: "contact",
- url: ""
- }, {
- icon: "../../static/mine/bzzx.png",
- title: "帮助中心",
- type: "navigate",
- url: "/subpages/helpList/helpList"
- }, {
- icon: "../../static/mine/gywm.png",
- title: "关于我们",
- type: "navigate",
- url: ""
- }]})
- },
- authorizationSuccessful() {
- console.log("授权成功");
- this.setData({ showAuthorizedDialog: false })
- this.checkAuth();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|