Micro letter applet cloud development entry to publish on-line

Initialize the project

Description [start] non-white Tutorials

For the crowd [proposed quick look at the document, facing write again]

  1. Read the official document, and simply wrote
  1. Familiar vue / es6

Applet registered letter public platform [micro]

Get appid [micro letter public platform - Development - Development Settings]

New applet cloud development projects

  1. New Item Select an empty directory, fill AppID (using cloud development capabilities must be filled AppID)
  2. Check the Create a "small cloud development program."
  3. Click New to get a sample applet showing basic cloud development capabilities.
  4. The small program with a small general QuickStart program with the following differences should be noted:
  • No tourist mode, you can not use the test numbers
  • project.config.json [] configuration tool has been added to specify the directory field cloudfunctionRoot cloud storage function
  • cloudfunctionRoot specified directory has a special icon
  • Cloud development capabilities from the ground began to support the library 2.2.3

Not specified environment [first use cloud development]

Before using cloud development capabilities need to open cloud development

Click the button cloud development, continue to click open and continue to agree to the terms

New Environment

Note : Specify the name of the environment, and the back can not be changed , can only build two environment [ID is automatically generated based on the name of the environment]

Modify app.js initialize the database environment [ID]

Environment ID as follows:

Project Directory

After the initialization directory

New Page Example

  • js [logic] page
  • json [configuration] page
  • wxml structure [page]
  • wxss [page style sheet]

app.json [ctrl + s Save]

New util folder

utils file code address

Entry file app.js

Js global public introduction, you can also be individually recited each page
app.js address code Code

Profiles

Global configuration [refers to] app.json

Here only I wrote some items used in other configurations refer to official documents

[End of page configuration page json file format] [agreement] is greater than the configuration

Page configuration can only be set content app.json section window configuration items, configuration item page will cover the same configuration items app.json in the window.

Cloud development including cloud function []

前面已经介绍了小程序端的一些基本配置及文件的介绍;
这篇来讲一下云开发,在初始化项目时已经开通了云开发功能。

云开发介绍

  1. 三大基础能力支持:
  • 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写自身业务逻辑代码
  • 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 数据库
  • 存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理【类似七牛的对象存储
  1. 云开发控制台

数据库周边

  • 每条记录都有一个_id字段用以唯一标志一条记录
  • 一个_openid字段用以标志记录的创建者,即小程序的用户【仅在小程序端创建才会生成此字段】
  • 开发者可以自定义 _id,但不可自定义和修改 _openid
  • 数据库 API 分为小程序端和服务端两部分,服务端相对小程序端操作,服务端权限大且更安全

权限控制

数据库的权限分为小程序端和管理端,管理端包括云函数端和控制台。

  • 小程序端运行在小程序中,读写数据库受权限控制限制,
  • 管理端运行在云函数上,拥有所有读写数据库的权限。云控制台的权限同管理端,拥有所有权限。

具体权限见云开发文档

开发示例

注意事项:使用集合必须是已存在的,所以得提前添加

  1. 创建第一个集合
  • 打开控制台,选择 "数据库" 标签页,通过 "添加集合" 入口创建一个集合。
  • 界面中我们可以添加记录、查找记录、管理索引和管理权限。
  1. 小程序端操作数据
  • 以下第一条红框代码:调用获取默认环境的数据库的引用【用node写过接口的同学可能一下就看明白了

  1. 服务端操作数据【云开发】
  • 新建云函数
  • 右键云函数根目录文件夹: 新建Node.js云函数,初始化如下

  • 云函数同步
  • 右键云函数文件夹:上传并部署:云端安装所有依赖
  • 云函数使用
  • 云函数可相互间调用
  • 云函数可小程序端使用,小程序端使用如下:

其它问题汇总

小程序端

自定义组件以及第三方组件的使用【见项目pages/index代码】

云开发

  1. 多个云函数环境切换繁琐,不能统一配置【感觉后面官方会退出更合适的方法】
  • 解决办法:tcb-router
  • 思路:建立一个云函数,通过不同的url寻找方法
  • 相关链接
  1. 本地调试繁琐
    没有尝试--!

入门项目【硬核天地】

安装使用

  1. 克隆代码到本地
git clone [email protected]:xushankun/yhtd-mp.git
  1. 打开“微信开发者工具”,导入项目
  2. 导入时填写自己的appid 或者导入后project.config.json 里更改appid

  3. 环境ID改为自己的【包括每个云函数index.js里的环境ID

  4. 数据库添加集合如下:
  • defriend【黑名单列表】
  • kklist【帖子列表】
  • services【功能控制开关】 字段:"isRelease":true
  • users【用户列表】

isRelease发布状态时改为false【规避微信审核,因为个人开发者禁止用户发布信息】

Guess you like

Origin www.cnblogs.com/xushankun/p/10984981.html