100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 微信小程序复杂条件判断按钮显示隐藏

微信小程序复杂条件判断按钮显示隐藏

时间:2019-04-17 23:32:31

相关推荐

微信小程序复杂条件判断按钮显示隐藏

背景概述:第二个和第三个view根据条件判断显示,第一个view根据条件判断是否在任一页面显示。

<view class="root"><view wx:if="{{(hasRecord || length > 0) && apiFinished }}" class="navigate-wrapper">***</view><view wx:if="{{hasAuth&& apiFinished}}">***</view><view wx:if="{{!hasAuth&& apiFinished}}" class="wrapper">***</view></view>

const {jvyxOptometryAuth, jvyxOptometryScanCode } = require("./services");const {getPersonalEyeByPin } = require("../optometry/service-optometry");const {noLogin,getPtKey,getPtPin,shareAppMessageConfig,} = require("../../../utils/util");Page({/*** 页面的初始数据*/data: {storeName: "",bizNumber: "",isLogin: false,login_pin: "",pt_key: "",apiFinished: false,hasAuth: false,hasRecord: false,length: 0,},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {options.q ="?storeId=25372208&Id=1234567887654321234565";let {q } = options;console.log(options, q);let params = q.split("?")[1].split("&");let paramsObj = {};for (let i of params) {paramsObj[i.split("=")[0]] = i.split("=")[1];}if (noLogin()) {let returnPage = "/pages/optometryService/showKey/showKey";wx.redirectTo({url: `/pages/login/index/index?returnPage=${encodeURIComponent(returnPage)}&q=${encodeURIComponent(q)}`,});} else {wx.showLoading({title: "加载中",});jvyxOptometryAuth({}).then((res) => {let {hasAuth, hasRecord } = res.data;hasAuth = true;this.setData({hasAuth,hasRecord,});// 值为真则发送两个请求if (hasAuth) {return Promise.all([jvyxOptometryScanCode({storeId: paramsObj["storeId"] }),getPersonalEyeByPin({}),]);} else {return getPersonalEyeByPin({});}}).then((res) => {// promise.all返回的结果为数组,判断返回结果if (Object.prototype.toString.call(res) === "[object Array]") {let [resScanCode, resEyeByPin] = res;const {bizNumber, storeName } = resScanCode.data;const length = resEyeByPin.data.length;this.setData({apiFinished: true,bizNumber,storeName,length,});} else {const {data } = res;this.setData({apiFinished: true,length: data.length,});}wx.hideLoading();}).catch((err) => {this.setData({apiFinished: true,});wx.hideLoading();});}},/*** 用户点击右上角分享*/onShareAppMessage: function () {return shareAppMessageConfig();},toOptometry: function () {wx.navigateTo({***});},});

背景:后来改了需求,要求第一个界面navigate-wrapper必须显示,第二个界面判断条件

<view class="root"><view wx:if="{{(hasAuth || (hasRecord || length > 0)) && apiFinished}}" class="navigate-wrapper">***</view><view wx:if="{{hasAuth&& apiFinished}}">***</view><view wx:if="{{!hasAuth&& apiFinished}}" class="wrapper">***</view></view>

const {jvyxOptometryAuth, jvyxOptometryScanCode } = require("./services");const {getPersonalEyeByPin } = require("../optometry/service-optometry");const {noLogin,getPtKey,getPtPin,shareAppMessageConfig,} = require("../../../utils/util");Page({/*** 页面的初始数据*/data: {storeName: "",bizNumber: "",isLogin: false,login_pin: "",pt_key: "",apiFinished: false,hasAuth: false,hasRecord: false,length: 0,},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {options.q ="?storeId=25372208&Id=1234567887654321234565";let {q } = options;console.log(options, q);let params = q.split("?")[1].split("&");let paramsObj = {};for (let i of params) {paramsObj[i.split("=")[0]] = i.split("=")[1];}if (noLogin()) {let returnPage = "/pages/optometryService/showKey/showKey";wx.redirectTo({url: `/pages/login/index/index?returnPage=${encodeURIComponent(returnPage)}&q=${encodeURIComponent(q)}`,});} else {wx.showLoading({title: "加载中",});jvyxOptometryAuth({}).then((res) => {let {hasAuth, hasRecord } = res.data;this.setData({hasAuth,hasRecord,});if (hasAuth) {return jvyxOptometryScanCode({storeId: paramsObj["storeId"] });} else {return getPersonalEyeByPin({});}}).then((res) => {// 上面第一个请求返回的res.data是对象,第二个请求则为arrayif (Object.prototype.toString.call(res.data) !== "[object Array]") {const {bizNumber, storeName } = res.data;this.setData({apiFinished: true,bizNumber,storeName,});} else {const length = res.data.length;this.setData({apiFinished: true,length,});}wx.hideLoading();}).catch((err) => {this.setData({apiFinished: true,});wx.hideLoading();});}},/*** 用户点击右上角分享*/onShareAppMessage: function () {return shareAppMessageConfig();},toOptometry: function () {wx.navigateTo({*** });},});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。