index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const { envList } = require('../../envList');
  2. // pages/me/index.js
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. openId: '',
  9. showTip: false,
  10. title:"",
  11. content:""
  12. },
  13. getOpenId() {
  14. wx.showLoading({
  15. title: '',
  16. });
  17. wx.cloud
  18. .callFunction({
  19. name: 'quickstartFunctions',
  20. data: {
  21. type: 'getOpenId',
  22. },
  23. })
  24. .then((resp) => {
  25. this.setData({
  26. haveGetOpenId: true,
  27. openId: resp.result.openid,
  28. });
  29. wx.hideLoading();
  30. })
  31. .catch((e) => {
  32. wx.hideLoading();
  33. const { errCode, errMsg } = e
  34. if (errMsg.includes('Environment not found')) {
  35. this.setData({
  36. showTip: true,
  37. title: "云开发环境未找到",
  38. content: "如果已经开通云开发,请检查环境ID与 `miniprogram/app.js` 中的 `env` 参数是否一致。"
  39. });
  40. return
  41. }
  42. if (errMsg.includes('FunctionName parameter could not be found')) {
  43. this.setData({
  44. showTip: true,
  45. title: "请上传云函数",
  46. content: "在'cloudfunctions/quickstartFunctions'目录右键,选择【上传并部署-云端安装依赖】,等待云函数上传完成后重试。"
  47. });
  48. return
  49. }
  50. });
  51. },
  52. gotoWxCodePage() {
  53. wx.navigateTo({
  54. url: `/pages/exampleDetail/index?envId=${envList?.[0]?.envId}&type=getMiniProgramCode`,
  55. });
  56. },
  57. });