06 Twenty-four

今天仔细看了看代码,觉得还有一些地方不太完善,需要给用户提供解绑账号的方式,同时查询用户注册信息只需要openid即可,账号密码已经验证过了,所以这里在验证用户账号与绑定账号信息不相符合时,还需要提供注销方式,这里采用wx.showModal弹出复选框,wx.showModal 与 wx.showToast可以同时显示,注意showModal显示前hidetoast.

需要设计新的注销界面,注销需要验证账号以及密码,成功后实现注销,同时注销界面也需要提供返回界面,防止用户误点击出不去。这个使用navigateto navigateback即可

1.修改之前的云函数

由于逻辑是先判断uid psw 是否符合,再判断openid 与uid 是否匹配,所以修改前面的云函数,只判断openid有无注册,不需要再添加uid pwd
注释uid pwd 即可
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  
  return await db.collection('test_bind').where({
    openid : event.openid,
    //  uid : event.uid,
    //  pwd : event.pwd
  }).get()
}

2. 构建新的注册按钮逻辑

账号密码符合数据库时,开始判断是否绑定openid,未绑定则添加绑定,绑定则分以下两种情况:
1.	绑定与输入用户一致,直接登陆
2.	绑定与输入用户不一致,提示是否需要解绑账号

中间需要注意this.setdata that.setdata (由于小程序的异步处理问题)
如:调取
	this.data.rectifyuid                   要加data,后面的前面定义的部分
  submitInfo: function(e){
    wx.showToast({
      title: "登录中...",
      icon: "loading",
      duration: 10000
    })
    var that = this;
    var uid = e.detail.value.uid;
    var pwd = e.detail.value.pwd;
    // var vcode = e.detail.value.vcode;
    if ((uid.length == 0 || pwd.length == 0)) {
      wx.showToast({
        title: '输入有误',
        image: '/images/info.png',
        icon: 'none',
        duration: 1000
      });
    } else {
      collection.where({
        uid : uid,
        pwd : pwd
      }).get({
        success: res => {
          if(res.data.length == 0 ){
            // console.log(res.data)
            wx.showToast({
              icon: 'none',
              title: '账号或密码错误'
            })
          }else{
            console.log('[数据库] [查询记录] 成功: ', res.data[0]['uid'])

            
            //云函数返回test_bind 中是否已有绑定信息
            wx.cloud.callFunction({
              name:'isRegistered',
              data:{
                openid : app.globalData.openid,
              },
              complete: res => {
                let length = res.result.data.length 
                console.log('[返回数据长度]length',length)

                //回调中处理数据解决异步问题
                if(length == 0){
                  //没绑定openid时添加绑定信息
                  //云函数绑定openid
                  wx.cloud.callFunction({
                    name: 'bindOpenid',
                    data: {
                      openid : app.globalData.openid,
                      uid : uid,
                      pwd : pwd
                    },
                    complete: res => {
                    console.log('callFunction test result: ', res)
                    }
                  })
                  //保存全局数据,跳转页面
                  app.globalData.uid = uid;
                  app.globalData.newpwd = pwd;
                  //设置本地Storage,维持登录态用
                  wx.setStorageSync('uid', uid);
                  wx.setStorageSync('newpwd', pwd);
                  wx.navigateTo({
                    //没这方面数据,瞎填一手
                    url: '/pages/welcome/welcome?uid=' + uid + '&name=' + 'XXX' + '&classroom=' + 'AI班',
                  })
                }else{
                  //已绑定用户
                  that.setData({
                    rectifyuid : res.result.data[0]['uid']
                  })
                  console.log('[rectify_uid]: ', this.data.rectifyuid)
                  if(length == 1 && uid == this.data.rectifyuid){
                    //绑定用于与输入uid相同,直接进入
                      //提示showModal时隐藏toast
                      wx.hideToast({
                        success: (res) => {},
                      })
                      //保存全局数据,跳转页面
                      app.globalData.uid = uid;
                      app.globalData.newpwd = pwd;
                      //设置本地Storage,维持登录态用
                      wx.setStorageSync('uid', uid);
                      wx.setStorageSync('newpwd', pwd);
                      wx.navigateTo({
                        //没这方面数据,瞎填一手
                        url: '/pages/welcome/welcome?uid=' + uid + '&name=' + 'XXX' + '&classroom=' + 'AI班',
                      })
                  }else{
                    //绑定的用户不是当前登陆账号
                    //提示showModal时隐藏toast
                    wx.hideToast({
                      success: (res) => {},
                    })
                    wx.showModal({
                      title: '警告',
                      content: '您已绑定其他账号,是否解绑账号',
                      success: function (res) {
                        if (res.confirm) {//这里是点击了确定以后

                          console.log('用户点击确定,解绑账号')
                          wx.navigateTo({
                            url: '/pages/index/unbind',
                          })
                        } else {//这里是点击了取消以后
                          console.log('用户点击取消,不解绑账号')
                        }
                      }
                    })
                  }
                }
              }
            })
          }
        },
        fail: err => {
          wx.showToast({
            icon: 'none',
            title: '查询记录失败'
          })
          console.error('[数据库] [查询记录] 失败:', err)
        }
      })
    }
  },

3. 增加新的删除云函数

注意不同云函数返回的res data 结构不同,利用console.log 打印出来观察处理
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
//反正只创建了一个环境,直接不设置env

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  //暂时设置为test_bind
  return await db.collection('test_bind').where({
    openid : event.openid,
     uid : event.uid,
     pwd : event.pwd
  }).remove()
}

4. 构建新的用于解除绑定的界面,

在原来注册见面上改一下就行,利用wx.showModel 提供跳转的对话框,使用navigate跳转及返回
添加了hide ,当学号长度超过12时自动隐藏键盘控制长度
加入 focus ,高亮选中对话框

5. 最终效果

解绑成功后自动返回注册界面,同时原来的想要绑定的新账户仍然在该处,直接绑定即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hive 中可以使用 UDF(User-Defined Functions)来实现将数字转化为英文格式的功能。以下是一个示例 UDF 的代码实现: ```java import org.apache.hadoop.hive.ql.exec.UDF; import java.text.DecimalFormat; public class NumberToEnglish extends UDF { private static final String[] tensNames = {"", " ten", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety"}; private static final String[] numNames = {"", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen"}; private static final String[] bigNames = {"", " thousand", " million", " billion"}; public String evaluate(Double num) { if (num == 0) { return "zero"; } DecimalFormat decimalFormat = new DecimalFormat("#.00"); String formatted = decimalFormat.format(num); String[] parts = formatted.split("\\."); long dollars = Long.parseLong(parts[0]); int cents = Integer.parseInt(parts[1]); String dollarsInEnglish = convert(dollars); String centsInEnglish = convert(cents); String result = dollarsInEnglish + " dollars"; if (cents != 0) { result += " and " + centsInEnglish + " cents"; } return result.trim(); } private static String convert(long num) { if (num == 0) { return "zero"; } String prefix = ""; if (num < 0) { num = -num; prefix = "negative"; } String current = ""; int place = 0; do { long n = num % 1000; if (n != 0) { String s = convertLessThanOneThousand((int) n); current = s + bigNames[place] + current; } place++; num /= 1000; } while (num > 0); return (prefix + current).trim(); } private static String convertLessThanOneThousand(int num) { String current; if (num % 100 < 20) { current = numNames[num % 100]; num /= 100; } else { current = numNames[num % 10]; num /= 10; current = tensNames[num % 10] + current; num /= 10; } if (num == 0) { return current; } return numNames[num] + " hundred" + current; } } ``` 这个 UDF 接受一个 Double 类型的参数,然后将其转化为英文格式的字符串。在这个 UDF 中,我们使用了一个叫做 `convert()` 的函数来将数值转化为英文形式。这个函数将数值按照千位进行分组,然后对每一组的数值进行转化,最后将所有组的结果拼接起来。 例如,要将 USD24,217.45 转化为英文格式,可以使用如下的 HiveQL 语句: ```sql SELECT NumberToEnglish(24217.45); ``` 上面的语句将返回字符串 "twenty-four thousand two hundred seventeen dollars and forty-five cents"。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值