Javascript编程 :编一个小程序 如何让它自动打开一个网页,然后间隔10秒再自动关闭这个网页。如此循环。

Javascript编程 :编一个小程序 如何让它自动打开一个网页,然后间隔10秒再自动关闭这个网页。如此循环。,第1张

var _iframe

function gostart(){

openPage()

setTimeout(function(){closePage()},2000)

}

function openPage(){

_iframe = document.createElement("iframe")

_iframe.src="http://www.baidu.com"

document.body.appendChild(_iframe)

}

function closePage(){

document.body.removeChild(_iframe)

}

自己通过setTimeout函数来控制循环,不懂setTimeout的话,去亩哪郑百度缓闭上搜索一下用法。迅颂

给分吧。^_^

多次拒绝登录和允许登录

微信小程序的登录获取用户信息,是通过微信d出窗口,用户可点击允许 和拒绝两个按钮,点击允许,则获取用户信息登录成功,若点击拒绝,闭毕则获取失败,可通过二次请轿掘芹求调散渗用d起获取用户信息窗口。

具体代码如下:

//app.js

App({

onLaunch: function () {

//调用API从本地缓存中获取数据

var logs = wx.getStorageSync('logs') || []

logs.unshift(Date.now())

wx.setStorageSync('logs', logs)

console.log('logs',logs)

},

getUserInfo:function(cb){

var that = this

//调用登录接口

function getOpenid(backMsg){

that.globalData.userInfo = backMsg.userInfo

that.globalData.encryptedData = backMsg.encryptedData

that.globalData.iv = backMsg.iv

that.globalData.login = true

console.log(that.globalData.code)

wx.request({

url:that.localUrl+'Login/sendCodeLogin',

data:{

code:that.globalData.code,

encryptedData: backMsg.encryptedData,

iv:backMsg.iv

},

success:function(openData){

console.log('返回openid',openData,openData.data)

if(openData.data.code==1001){

that.globalData.openid = openData.data.data.openid

wx.setStorageSync('openid',that.globalData.openid)

wx.setStorageSync('userInfo',that.globalData.userInfo)

wx.setStorageSync('isManager', openData.data.data.isManager)

wx.showToast({

title: '登录成功',

icon: 'success',

duration: 500

})

typeof cb == "function" &&cb(that.globalData.userInfo)

}else{

wx.showLoading({

title: '登录失败'

})

setTimeout(function () {

wx.hideLoading()

}, 500)

}

}

})

}

wx.login({

success: function (msg) {

console.log('code',msg)

if(msg.code){

that.globalData.code = msg.code

if(that.globalData.login==false){

wx.openSetting({

success: function (data) {

if(data) {

if (data.authSetting["scope.userInfo"] == true) {

//loginStatus = true

wx.getUserInfo({

withCredentials: false,

success: function (res) {

console.log('第二次成功',res)

getOpenid(res)

},

fail: function (res) {

that.globalData.login = false

console.log('二次失败',res)

}

})

}else{

that.globalData.login = false

console.log('二次失败02')

}

}

},

fail: function () {

console.info("设置失败返回数据")

}

})

}else{

wx.getUserInfo({

success: function (res) {

console.log('第一次成功',res)

getOpenid(res)

},fail:function(msg){

that.globalData.login = false

console.log('第一次失败',msg)

}

})

}

}

},

fail:function(res){

console.log(res)

}

})

},

globalData:{

userInfo:null,

encryptedData:null,

iv:null,

openid:null,

code:null

}

})

 <button bindtap="powerDrawer" type="primary" size="mini" style="width: 55%" data-statu="open">中奖记录</button>  

<!-- 中间名单d窗 -->

<view class="drawer_div">

  <view class="drawer_screen" bindtap="powerDrawer" data-statu="close" wx:if="{{showModalStatus}}"></view>

    <view animation="{{animationPrize}}" class="drawer_box" wx:if="{{showModalStatus}}">

      <view class="drawer_title">

        中奖记录

        <image src="../img/x@2x.png" bindtap="powerDrawer" data-statu="close"></image>

      </view>

      <view class="drawer_content">

        <view class="top grid">

          <text>

            名称:啦啦啦啦啦啦啦啦

          </text>

          <text>

            时间:2020-02-20

          </text>

        </view>

        <view class="top grid">

          <text>

            名称:啦啦啦啦啦啦啦啦

          </text>

          <text>

            时间:2020-02-20

          </text>

        </让岩view>

    </view>

  </view>

</view>

.drawer_screen {

  width: 100%

  height: 100%

  position: fixed

  top: 0

  left: 0

  z-index: 1000

  background: #000

  opacity: 0.5

  overflow: hidden

}

/*content*/

.drawer_box {

  width: 650rpx

  overflow: hidden

  position: fixed

  top: 50%

  left: 0

  z-index: 1001

  background: #FAFAFA

  margin: -150px 50rpx 0 50rpx

  border-radius: 3px

}

.drawer_title{

  padding:30rpx 20rpx

  font-size: 36rpx

  text-align: center

  position: relative

}

.drawer_title 郑扰image{

  display: inline-block

  width: 30rpx

  height: 30rpx

  position: absolute

  right: 9px

  top: 10px

}

.drawer_content {

  height: 210px

  overflow-y: scroll /*超出父盒子高度可滚动*/

  padding: 0 20rpx

}

.top{

  display: flex

  justify-content: space-between

  border-bottom: 1px dashed #ccc

}

.top text{

  display: inline-block

  height: 60rpx

  line-height: 20rpx

}

data: {

animationPrize: {},

}

powerDrawer: function (e) {

    // console.log(e)

    let currentStatu = e.currentTarget.dataset.statu

    this.util(currentStatu)

  },

  util: function (currentStatu) {

 坦丛御   /* 动画部分 */

    // 第1步:创建动画实例

    var animation = wx.createAnimation({

      duration: 200,  //动画时长

      timingFunction: "linear", //线性

      delay: 0  //0则不延迟

    })

    // 第2步:这个动画实例赋给当前的动画实例

    this.animation = animation

    // 第3步:执行第一组动画

    animation.opacity(0).rotateX(-100).step()

    // 第4步:导出动画对象赋给数据对象储存

    this.setData({

      animationPrize: animation.export()

    })

    // 第5步:设置定时器到指定时候后,执行第二组动画

    setTimeout(function () {

      // 执行第二组动画

      animation.opacity(1).rotateX(0).step()

      // 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象

      this.setData({

        animationPrize: animation

      })

      //关闭

      if (currentStatu == "close") {

        this.setData({

          showModalStatus: false

        })

      }

    }.bind(this), 200)

    // 显示

    if (currentStatu == "open") {

      this.setData({

        showModalStatus: true

      })

    }

  },


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8234957.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存