前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >六娃密码管理小程序开发经验总结

六娃密码管理小程序开发经验总结

作者头像
拿我格子衫来
发布2022-01-24 09:26:28
3390
发布2022-01-24 09:26:28
举报
文章被收录于专栏:TopFE

昨天晚上 利用下班后的三个小时,做了一个密码管理的小程序,使用云开发,搭配云函数

小程序只要两个页面,一个新增,一个列表

该项目我已经开源了, 项目地址:https://github.com/PmcFizz/FasterCoder

主要js代码 新增代码

代码语言:javascript
复制
 // 输入双向绑定
  bindAppNameInput (e) {
    this.setData({
      appName: e.detail.value
    })  
  },
  // 输入双向绑定
  bindAccountInput (e) {
    this.setData({
      account: e.detail.value
    })  
  },
  // 输入双向绑定
  bindPasswordInput (e) {
    this.setData({
      password: e.detail.value
    })  
  },
  toList () {
    wx.redirectTo({
      url: '../pwdList/pwdList',
    })
  },
  // 提交数据
  formSubmit () {
     const db = wx.cloud.database()
     let appName = this.data.appName
     let account = this.data.account
     let password = this.data.password
     let openid = getApp().globalData.openid
     db.collection('pwdBox')
       .add({ data: { appName, account, password, openid}})
       .then(res=>{         
          wx.showToast({
            title: '新增成功',
            icon: 'success',
            duration: 2000
          })
          wx.redirectTo({
            url: '../pwdList/pwdList',
          })        
       })
  },

查询列表代码:

代码语言:javascript
复制
 onLoad: function (options) {
    let self = this
    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        app.globalData.openid = res.result.openid
        const db = wx.cloud.database()
        let openid = res.result.openid
        db.collection('pwdBox')
          .where({ openid }).get({
            success(res) {
              self.setData({
                pwdList: res.data
              })
            }
          })
      },
      fail: err => {
        console.error('[云函数] [login] 调用失败', err)
        wx.navigateTo({
          url: '../deployFunctions/deployFunctions',
        })
      }
    })
  },

一个新增函数, 一个查询函数,

另外,使用云函数获取 用户的openid 作为用户的唯一主键,作为查询条件 获取用户openid 的云函数如下

代码语言:javascript
复制
wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        app.globalData.openid = res.result.openid
      }
})
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
访问管理
访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档