123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- // index.js
- // const app = getApp()
- const { envList } = require('../../envList.js');
- Page({
- data: {
- showUploadTip: false,
- powerList: [{
- title: '云函数',
- tip: '安全、免鉴权运行业务代码',
- showItem: false,
- item: [{
- title: '获取OpenId',
- page: 'getOpenId'
- },
- // {
- // title: '微信支付'
- // },
- {
- title: '生成小程序码',
- page: 'getMiniProgramCode'
- },
- // {
- // title: '发送订阅消息',
- // }
- ]
- }, {
- title: '数据库',
- tip: '安全稳定的文档型数据库',
- showItem: false,
- item: [{
- title: '创建集合',
- page: 'createCollection'
- }, {
- title: '更新记录',
- page: 'updateRecord'
- }, {
- title: '查询记录',
- page: 'selectRecord'
- }, {
- title: '聚合操作',
- page: 'sumRecord'
- }]
- }, {
- title: '云存储',
- tip: '自带CDN加速文件存储',
- showItem: false,
- item: [{
- title: '上传文件',
- page: 'uploadFile'
- }]
- }, {
- title: '云后台',
- tip: '开箱即用的小程序后台管理系统',
- tag: 'new',
- page: 'cloudBackend',
- }, {
- title: '单页模板2.0',
- tip: '基于页面模板,快速配置、搭建小程序页面',
- tag: 'new',
- page: 'singleTemplate',
- }, {
- title: '云托管',
- tip: '不限语言的全托管容器服务',
- link: 'https://cloud.weixin.qq.com/cloudrun',
- }],
- envList,
- selectedEnv: envList[0],
- haveCreateCollection: false
- },
- onClickPowerInfo(e) {
- const index = e.currentTarget.dataset.index;
- const powerList = this.data.powerList;
- const selectedItem = powerList[index];
- selectedItem.showItem = !selectedItem.showItem;
- if (selectedItem.link) {
- wx.navigateTo({
- url: `../web/index?url=${selectedItem.link}&title=${selectedItem.title}`,
- });
- } else if (selectedItem.page) {
- wx.navigateTo({
- url: `/pages/${selectedItem.page}/index`,
- });
- } else if (selectedItem.title === '数据库' && !this.data.haveCreateCollection) {
- this.onClickDatabase(powerList);
- } else {
- this.setData({
- powerList
- });
- }
- },
- onChangeShowEnvChoose() {
- wx.showActionSheet({
- itemList: this.data.envList.map(i => i.alias),
- success: (res) => {
- this.onChangeSelectedEnv(res.tapIndex);
- },
- fail (res) {
- console.log(res.errMsg);
- }
- });
- },
- onChangeSelectedEnv(index) {
- if (this.data.selectedEnv.envId === this.data.envList[index].envId) {
- return;
- }
- const powerList = this.data.powerList;
- powerList.forEach(i => {
- i.showItem = false;
- });
- this.setData({
- selectedEnv: this.data.envList[index],
- powerList,
- haveCreateCollection: false
- });
- },
- jumpPage(e) {
- wx.navigateTo({
- url: `/pages/${e.currentTarget.dataset.page}/index?envId=${this.data.selectedEnv.envId}`,
- });
- },
- onClickDatabase(powerList) {
- wx.showLoading({
- title: '',
- });
- wx.cloud.callFunction({
- name: 'quickstartFunctions',
- config: {
- env: this.data.selectedEnv.envId
- },
- data: {
- type: 'createCollection'
- }
- }).then((resp) => {
- if (resp.result.success) {
- this.setData({
- haveCreateCollection: true
- });
- }
- this.setData({
- powerList
- });
- wx.hideLoading();
- }).catch((e) => {
- console.log(e);
- this.setData({
- showUploadTip: true
- });
- wx.hideLoading();
- });
- }
- });
|