一文带你了解小程序中的权限设计

  /**

  * 可通过 app 获取或修改全局应用的 变量 状态 等信息

  * 具体可以console.info 在编辑器Console面板查看更多信息

  * 如果需要 async-await,请在方法前 async

  **/

  export default {

  async onAppLaunch(launchOpts) {

  //console.log('---------> LifeCycle onAppLaunch', launchOpts)

  const { OPENID, FROM_OPENID } = await app.utils.getWXContext()

  let userId = FROM_OPENID || OPENID

  if (!userId) {

  console.log("userId",userId)

  const { wedaId } = await app.cloud.getUserInfo()

  userId = wedaId

  }

  app.dataset.state.openid = userId

  console.log("openid",app.dataset.state.openid)

  const result = await app.cloud.callModel({

  name: 'yhb_0xbca5z',

  methodName: 'wedaGetRecords',

  params: {

  "where": [

  {

  "key": "openid",

  "rel": "eq",

  "val": app.dataset.state.openid

  }

  ]

  }, // 方法入参

  });

  if(result.total>=1){

  app.dataset.state.isRegister = true

  let role = result.records[0].js

  console.log("role",role)

  if(role=="2"){

  app.dataset.state.isAdmin = true

  }else{

  app.dataset.state.isAdmin = false

  }

  }else{

  app.dataset.state.isRegister = false

  }

  },

  onAppShow(appShowOpts) {

  //console.log('---------> LifeCycle onAppShow', appShowOpts)

  },

  onAppHide() {

  //console.log('---------> LifeCycle onAppHide')

  },

  onAppError(options) {

  //console.log('---------> LifeCycle onAppError', options)

  },

  onAppPageNotFound(options) {

  //console.log('---------> LifeCycle onAppPageNotFound', options)

  },

  onAppUnhandledRejection(options) {

  //console.log('---------> LifeCycle onAppUnhandledRejection', options)

  }

  }