index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // index.js
  2. // const app = getApp()
  3. const { envList } = require('../../envList.js');
  4. Page({
  5. data: {
  6. showUploadTip: false,
  7. powerList: [{
  8. title: '云函数',
  9. tip: '安全、免鉴权运行业务代码',
  10. showItem: false,
  11. item: [{
  12. title: '获取OpenId',
  13. page: 'getOpenId'
  14. },
  15. // {
  16. // title: '微信支付'
  17. // },
  18. {
  19. title: '生成小程序码',
  20. page: 'getMiniProgramCode'
  21. },
  22. // {
  23. // title: '发送订阅消息',
  24. // }
  25. ]
  26. }, {
  27. title: '数据库',
  28. tip: '安全稳定的文档型数据库',
  29. showItem: false,
  30. item: [{
  31. title: '创建集合',
  32. page: 'createCollection'
  33. }, {
  34. title: '更新记录',
  35. page: 'updateRecord'
  36. }, {
  37. title: '查询记录',
  38. page: 'selectRecord'
  39. }, {
  40. title: '聚合操作',
  41. page: 'sumRecord'
  42. }]
  43. }, {
  44. title: '云存储',
  45. tip: '自带CDN加速文件存储',
  46. showItem: false,
  47. item: [{
  48. title: '上传文件',
  49. page: 'uploadFile'
  50. }]
  51. }, {
  52. title: '云后台',
  53. tip: '开箱即用的小程序后台管理系统',
  54. tag: 'new',
  55. page: 'cloudBackend',
  56. }, {
  57. title: '单页模板2.0',
  58. tip: '基于页面模板,快速配置、搭建小程序页面',
  59. tag: 'new',
  60. page: 'singleTemplate',
  61. }, {
  62. title: '云托管',
  63. tip: '不限语言的全托管容器服务',
  64. link: 'https://cloud.weixin.qq.com/cloudrun',
  65. }],
  66. envList,
  67. selectedEnv: envList[0],
  68. haveCreateCollection: false
  69. },
  70. onClickPowerInfo(e) {
  71. const index = e.currentTarget.dataset.index;
  72. const powerList = this.data.powerList;
  73. const selectedItem = powerList[index];
  74. selectedItem.showItem = !selectedItem.showItem;
  75. if (selectedItem.link) {
  76. wx.navigateTo({
  77. url: `../web/index?url=${selectedItem.link}&title=${selectedItem.title}`,
  78. });
  79. } else if (selectedItem.page) {
  80. wx.navigateTo({
  81. url: `/pages/${selectedItem.page}/index`,
  82. });
  83. } else if (selectedItem.title === '数据库' && !this.data.haveCreateCollection) {
  84. this.onClickDatabase(powerList);
  85. } else {
  86. this.setData({
  87. powerList
  88. });
  89. }
  90. },
  91. onChangeShowEnvChoose() {
  92. wx.showActionSheet({
  93. itemList: this.data.envList.map(i => i.alias),
  94. success: (res) => {
  95. this.onChangeSelectedEnv(res.tapIndex);
  96. },
  97. fail (res) {
  98. console.log(res.errMsg);
  99. }
  100. });
  101. },
  102. onChangeSelectedEnv(index) {
  103. if (this.data.selectedEnv.envId === this.data.envList[index].envId) {
  104. return;
  105. }
  106. const powerList = this.data.powerList;
  107. powerList.forEach(i => {
  108. i.showItem = false;
  109. });
  110. this.setData({
  111. selectedEnv: this.data.envList[index],
  112. powerList,
  113. haveCreateCollection: false
  114. });
  115. },
  116. jumpPage(e) {
  117. wx.navigateTo({
  118. url: `/pages/${e.currentTarget.dataset.page}/index?envId=${this.data.selectedEnv.envId}`,
  119. });
  120. },
  121. onClickDatabase(powerList) {
  122. wx.showLoading({
  123. title: '',
  124. });
  125. wx.cloud.callFunction({
  126. name: 'quickstartFunctions',
  127. config: {
  128. env: this.data.selectedEnv.envId
  129. },
  130. data: {
  131. type: 'createCollection'
  132. }
  133. }).then((resp) => {
  134. if (resp.result.success) {
  135. this.setData({
  136. haveCreateCollection: true
  137. });
  138. }
  139. this.setData({
  140. powerList
  141. });
  142. wx.hideLoading();
  143. }).catch((e) => {
  144. console.log(e);
  145. this.setData({
  146. showUploadTip: true
  147. });
  148. wx.hideLoading();
  149. });
  150. }
  151. });