From 158a6a11ca113df9bcbd668a8bff6ac40c6489fc Mon Sep 17 00:00:00 2001 From: VK <370725567@qq.com> Date: Mon, 26 Oct 2020 14:20:44 +0800 Subject: [PATCH] 1.4.7 --- README.md | 2 +- README/1.2/1.2.3.md | 4 +- README/1.3/1.3.2.md | 4 +- README/1.4/1.4.7.md | 7 ++ .../router/package-lock.json | 6 +- cloudfunctions-aliyun/router/package.json | 2 +- .../pub/getComponentsDynamicData.js | 2 +- .../service/components_dynamic/pub/init.js | 2 +- .../router/service/db_test/pub/Promise.all.js | 2 +- .../router/service/db_test/pub/add.js | 2 +- .../router/service/db_test/pub/adds.js | 2 +- .../router/service/db_test/pub/del.js | 6 +- .../router/service/db_test/pub/geo.js | 1 - .../router/service/db_test/pub/getList.js | 6 +- .../router/service/db_test/pub/select.js | 5 +- .../router/service/db_test/pub/select2-2.js | 67 ------------------- .../router/service/db_test/pub/select2.js | 4 +- .../db_test/pub/select2_many-to-one.js | 12 ++-- .../db_test/pub/select2_one-to-many.js | 23 ++++--- package-lock.json | 6 +- package.json | 2 +- 21 files changed, 53 insertions(+), 114 deletions(-) create mode 100644 README/1.4/1.4.7.md delete mode 100644 cloudfunctions-aliyun/router/service/db_test/pub/select2-2.js diff --git a/README.md b/README.md index 4f054b9..0ca18c3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ### uniCloud云函数路由框架研究Q群:22466457 如有问题或建议可以在群内讨论。 ### 插件名称:`vk-unicloud-router` ### 作者:VK -### 更新时间:2020-10-23 +### 更新时间:2020-10-26 ## 主要功能 以及 对开发者的价值 #### 1、实现云函数路由模式 diff --git a/README/1.2/1.2.3.md b/README/1.2/1.2.3.md index e592e40..b5d6c98 100644 --- a/README/1.2/1.2.3.md +++ b/README/1.2/1.2.3.md @@ -63,7 +63,7 @@ res.item = await vk.baseDao.findByWhereJson({ // 分页查询多条数据 sql: select * from vk-test where money >= 0 limit 0,20; let res = await vk.baseDao.select({ dbName:"vk-test", // 表名 - pageKey:true, // 是否分页 + getCount:true, // 是否同时返回总数(会执行count) pageIndex:1, // 当前第几页 pageSize:20, // 每页条数 whereJson:{ // 条件 @@ -95,7 +95,7 @@ let res = await vk.baseDao.select2({ foreignKey:"kehuid", // 主表用于和副表连接的外键字段名 foreignKey2:"_id", // 副表用于和主表连接的外键字段名 as:"kehuInfo", // 副表信息插入到主表里的字段名称,如果输入记录中本来就已有该字段,则该字段会被覆写 - pageKey:true, // 是否分页 + getCount:true, // 是否同时返回总数(会执行count) pageIndex:1, // 当前第几页 pageSize:10, // 每页显示数量 whereJson:{ // 主表筛选条件 diff --git a/README/1.3/1.3.2.md b/README/1.3/1.3.2.md index 3cb0abe..6db4e9f 100644 --- a/README/1.3/1.3.2.md +++ b/README/1.3/1.3.2.md @@ -13,7 +13,7 @@ let res = await vk.baseDao.select2({ foreignKey:"kehuid", // 主表外键字段名 foreignKey2:"_id", // 副表外键字段名 as:"kehuInfo", // 副表数据插入到主表的字段名 - pageKey:true, // 是否分页(会返回count和hasMore) + getCount:true, // 是否同时返回总数(会执行count) pageIndex:1, // 当前第几页 pageSize:10, // 每页显示数据 whereJson:{ // 主表where条件 @@ -61,7 +61,7 @@ let res = await vk.baseDao.select2({ foreignKey:"_id", // 主表外键字段名 foreignKey2:"kehuid", // 副表外键字段名 as:"kehuInfo", // 副表数据插入到主表的字段名 - pageKey:true, // 是否分页(会返回count和hasMore) + getCount:true, // 是否同时返回总数(会执行count) pageIndex:1, // 当前第几页 pageSize:10, // 每页显示数据 fieldJson:{ // 主表字段显示规则 diff --git a/README/1.4/1.4.7.md b/README/1.4/1.4.7.md new file mode 100644 index 0000000..79337cb --- /dev/null +++ b/README/1.4/1.4.7.md @@ -0,0 +1,7 @@ +### uniCloud 云函数路由研究群:22466457 如有问题或建议可以在群内讨论。 +##### gitee公共仓库地址:https://gitee.com/vk-uni/vk-uni-cloud-router.git +### 更新内容 +##### 1、【新增】API `vk.callFunctionUtil.updateRequestGlobalParam` 用于设置全局公共请求参数(即每次请求云函数都会额外带上这些参数) +##### 如: 多店系统中,每次请求都要带上`shop_id`,就可以将 `shop_id` 设置为全局请求参数。设置后,就不需要在每个请求中手动传 `shop_id`了。 + +### 你也可以在评论区发布留言交流心得。 \ No newline at end of file diff --git a/cloudfunctions-aliyun/router/package-lock.json b/cloudfunctions-aliyun/router/package-lock.json index 697afd4..698e6ef 100644 --- a/cloudfunctions-aliyun/router/package-lock.json +++ b/cloudfunctions-aliyun/router/package-lock.json @@ -129,9 +129,9 @@ "version": "file:../common/uni-id" }, "vk-unicloud": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/vk-unicloud/-/vk-unicloud-1.6.8.tgz", - "integrity": "sha512-pTjCYrRFNkBjNaX3laK/Ck/an7JlnJcLfh9NK/2G80jsLcxVGEQCPL5DXxzl5oazCMZnS8jB1996LNj0SWhKRg==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/vk-unicloud/-/vk-unicloud-1.7.2.tgz", + "integrity": "sha512-Xe/Jn6zy9tlkX+5AVaI00R+Rpk7IJZ0ewgxEufZIRo0GSXZksIn3Tn4f7T1FBrG0MQrrOBUaHi5zWIeTfyk8/g==", "requires": { "@alicloud/pop-core": "^1.7.9", "form-data": "^3.0.0", diff --git a/cloudfunctions-aliyun/router/package.json b/cloudfunctions-aliyun/router/package.json index 06ffccd..bbbe898 100644 --- a/cloudfunctions-aliyun/router/package.json +++ b/cloudfunctions-aliyun/router/package.json @@ -12,7 +12,7 @@ "dependencies": { "config": "file:../common/config", "uni-id": "file:../common/uni-id", - "vk-unicloud": "^1.6.8" + "vk-unicloud": "^1.7.3" }, "private": true } diff --git a/cloudfunctions-aliyun/router/service/components_dynamic/pub/getComponentsDynamicData.js b/cloudfunctions-aliyun/router/service/components_dynamic/pub/getComponentsDynamicData.js index 341236a..4d09754 100644 --- a/cloudfunctions-aliyun/router/service/components_dynamic/pub/getComponentsDynamicData.js +++ b/cloudfunctions-aliyun/router/service/components_dynamic/pub/getComponentsDynamicData.js @@ -25,7 +25,7 @@ module.exports = { // 根据ids获取组件动态数据列表 let res_select = await vk.baseDao.select({ dbName:"opendb-components-dynamic", - pageKey:false, + getCount:false, pageSize:100, whereJson:{ data_id : _.in(ids) diff --git a/cloudfunctions-aliyun/router/service/components_dynamic/pub/init.js b/cloudfunctions-aliyun/router/service/components_dynamic/pub/init.js index 157329b..dde5403 100644 --- a/cloudfunctions-aliyun/router/service/components_dynamic/pub/init.js +++ b/cloudfunctions-aliyun/router/service/components_dynamic/pub/init.js @@ -32,7 +32,7 @@ module.exports = { }; res = await vk.baseDao.select({ dbName:dbName, - pageKey:true, + getCount:true, pageIndex:1, pageSize:100, whereJson:whereJson diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/Promise.all.js b/cloudfunctions-aliyun/router/service/db_test/pub/Promise.all.js index 01ed402..1d2dc0d 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/Promise.all.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/Promise.all.js @@ -29,7 +29,7 @@ module.exports = { dataJson:{ "money": 10.02+i, "_add_time": 1597456395010+i, - "kehuid": "001" + "user_id": "001" } }, event.util); tasks.push(promise); diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/add.js b/cloudfunctions-aliyun/router/service/db_test/pub/add.js index 60f1dd3..f61df07 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/add.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/add.js @@ -26,7 +26,7 @@ module.exports = { dbName:"vk-test", dataJson:{ "money": Math.floor(Math.random() * 9 + 1), - "kehuid": "001", + "user_id": "001", "location":new db.Geo.Point(longitude, latitude), "position":{ "longitude":longitude, diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/adds.js b/cloudfunctions-aliyun/router/service/db_test/pub/adds.js index 4e9114b..59f72bb 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/adds.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/adds.js @@ -32,7 +32,7 @@ module.exports = { // 随机定位结束----------------------------------------------------------- dataArr.push({ "money": Math.floor(Math.random() * 9 + 1), - "kehuid": "001", + "user_id": "001", "location":new db.Geo.Point(longitude, latitude), "position":{ "longitude":longitude, diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/del.js b/cloudfunctions-aliyun/router/service/db_test/pub/del.js index 89d4c76..579ec71 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/del.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/del.js @@ -20,16 +20,16 @@ module.exports = { /** * 这里为了防止误删,故vk.baseDao.del API * 会判断如果whereJson为空,则不执行删除操作 - * 所以这里加了个kehuid:_.neq("___")条件来达到删除全部的功能(实际开发时慎用删除全部功能) + * 所以这里加了个user_id:_.neq("___")条件来达到删除全部的功能(实际开发时慎用删除全部功能) */ res.num = await vk.baseDao.del({ dbName:"vk-test", whereJson:{ - kehuid:_.neq("___") + user_id:_.neq("___") } },event.util); // 对应的sql: - // delete from vk-test where kehuid != '___' + // delete from vk-test where user_id != '___' // 业务逻辑结束----------------------------------------------------------- return res; } diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/geo.js b/cloudfunctions-aliyun/router/service/db_test/pub/geo.js index 0c33322..32f1cae 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/geo.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/geo.js @@ -19,7 +19,6 @@ module.exports = { // 业务逻辑开始----------------------------------------------------------- res = await vk.baseDao.select({ dbName:"vk-test", - pageKey:true, pageIndex:1, pageSize:100, whereJson:{ diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/getList.js b/cloudfunctions-aliyun/router/service/db_test/pub/getList.js index e7c031d..4274909 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/getList.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/getList.js @@ -21,11 +21,10 @@ module.exports = { let { data = {}, util, originalParam } = event; let { uniID, pubFun, vk , db, _ } = util; let { uid } = data; - let res = {code : -1, msg : ''}; + let res = {code : 0, msg : ''}; // 业务逻辑开始----------------------------------------------------------- // 可写与数据库的交互逻辑等等 - let {pageNum, pageSize, addTimeLong ,endTimeLong, searchvalue} = data; - // 仅限以下表允许不登录查看 + let { pageNum, pageSize, addTimeLong ,endTimeLong, searchvalue } = data; let dbName = "vk-test"; let fieldJson = {}; let whereJson = {}; @@ -55,7 +54,6 @@ module.exports = { // 查询条件结束----------------------------------------------------------- res = await vk.baseDao.select({ dbName:dbName, - pageKey:true, pageIndex:pageNum, pageSize:pageSize, fieldJson:fieldJson, diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/select.js b/cloudfunctions-aliyun/router/service/db_test/pub/select.js index ecb4f7e..d57b4e7 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/select.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/select.js @@ -19,15 +19,14 @@ module.exports = { // 业务逻辑开始----------------------------------------------------------- res = await vk.baseDao.select({ dbName:"vk-test", - pageKey:true, pageIndex:1, pageSize:100, whereJson:{ - kehuid:"001" + user_id:"001" }, }, event.util); // 对应的sql: - // select * from vk-test where kehuid == '001' limit 0,100; + // select * from vk-test where user_id == '001' limit 0,100; // 业务逻辑结束----------------------------------------------------------- return res; } diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/select2-2.js b/cloudfunctions-aliyun/router/service/db_test/pub/select2-2.js deleted file mode 100644 index d96608b..0000000 --- a/cloudfunctions-aliyun/router/service/db_test/pub/select2-2.js +++ /dev/null @@ -1,67 +0,0 @@ -module.exports = { - /** - * 连表查询(仅限两表查询)(VK版本) - * @url db_test/pub/select2-2 前端调用的url参数地址 - * @description 此函数描述 - * @params {Object} data 请求参数 - * @params {String} uniIdToken 用户token - * @params {Object} util 公共工具包 - * data 请求参数 说明 - * res 返回参数说明 - * @params {Number} code 错误码,0表示成功 - * @params {String} msg 详细信息 - */ - main: async (event) => { - let { data = {}, userInfo, util, originalParam } = event; - let { uniID, pubFun, vk , db, _ } = util; - let { uid } = data; - let res = { code : 0, msg : 'ok' }; - // 业务逻辑开始----------------------------------------------------------- - const $ = _.aggregate; - let dbName = "gy-dp-kehu"; - let dbName2 = "uni-id-users"; - res = await db.collection(dbName).aggregate() - .lookup({ - from: dbName2, - let: { - order_book: '$book', - order_quantity: '$quantity' - }, - pipeline: $.pipeline() - .match(_.expr($.and([ - $.eq(['$title', '$$order_book']), - $.gte(['$stock', '$$order_quantity']) - ]))) - .project({ - _id: false, - title: false, - stock: true - }) - .done(), - as: 'user_info', - }) - .end(); - - // res = await vk.baseDao.select2({ - // dbName:"vk-test", - // dbName2:"uni-id-users", - // foreignKey:"kehuid", - // foreignKey2:"_id", - // as:"kehuInfo", - // pageKey:true, - // pageIndex:1, - // pageSize:10, - // whereJson:{ - - // }, - // fieldJson2:{ - // token:false, - // password:false, - // } - // }, event.util); - //console.log(res.rows.length); - - // 业务逻辑结束----------------------------------------------------------- - return res; - } -} \ No newline at end of file diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/select2.js b/cloudfunctions-aliyun/router/service/db_test/pub/select2.js index ce138b7..bcdfac8 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/select2.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/select2.js @@ -21,10 +21,10 @@ module.exports = { dbName:"vk-test", dbName2:"uni-id-users", foreignKeyType:"many-to-one", // one-to-many 一对多 many-to-one 多对一 - foreignKey:"kehuid", + foreignKey:"user_id", foreignKey2:"_id", as:"kehuInfo", - pageKey:true, + getCount:true, pageIndex:1, pageSize:10, whereJson:{ diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/select2_many-to-one.js b/cloudfunctions-aliyun/router/service/db_test/pub/select2_many-to-one.js index 22b8d97..8d609b2 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/select2_many-to-one.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/select2_many-to-one.js @@ -1,7 +1,7 @@ module.exports = { /** * 连表查询(仅限两表查询)(VK版本) - * @url db_test/pub/select2 前端调用的url参数地址 + * @url db_test/pub/select2_many-to-one 前端调用的url参数地址 * @description 此函数描述 * @params {Object} data 请求参数 * @params {String} uniIdToken 用户token @@ -21,17 +21,17 @@ module.exports = { dbName:"vk-test", // 主表名 dbName2:"uni-id-users", // 副表名 foreignKeyType:"many-to-one", // one-to-many 一对多 many-to-one 多对一 - foreignKey:"kehuid", // 主表外键字段名 + foreignKey:"user_id", // 主表外键字段名 foreignKey2:"_id", // 副表外键字段名 - as:"kehuInfo", // 副表数据插入到主表的字段名 - pageKey:true, // 是否分页(会返回count和hasMore) + as:"userInfo", // 副表数据插入到主表的字段名 + getCount:false, // 是否同时返回总数(会执行count) pageIndex:1, // 当前第几页 pageSize:10, // 每页显示数据 whereJson:{ // 主表where条件 }, whereJson2:{ // 副表where条件 - nickname : "测试客户1" + }, fieldJson:{ // 主表字段显示规则 @@ -40,7 +40,7 @@ module.exports = { token : false, password : false }, - sortArr:[ // 排序规则 + sortArr:[ // 主表排序规则(多对一,副表无排序规则) { "name":"money", "type":"desc" diff --git a/cloudfunctions-aliyun/router/service/db_test/pub/select2_one-to-many.js b/cloudfunctions-aliyun/router/service/db_test/pub/select2_one-to-many.js index 9991b70..9771eaf 100644 --- a/cloudfunctions-aliyun/router/service/db_test/pub/select2_one-to-many.js +++ b/cloudfunctions-aliyun/router/service/db_test/pub/select2_one-to-many.js @@ -1,7 +1,7 @@ module.exports = { /** * 连表查询(仅限两表查询)(VK版本) - * @url db_test/pub/select2 前端调用的url参数地址 + * @url db_test/pub/select2_one-to-many 前端调用的url参数地址 * @description 此函数描述 * @params {Object} data 请求参数 * @params {String} uniIdToken 用户token @@ -22,11 +22,17 @@ module.exports = { dbName2:"vk-test", // 副表名 foreignKeyType:"one-to-many", // one-to-many 一对多 many-to-one 多对一 foreignKey:"_id", // 主表外键字段名 - foreignKey2:"kehuid", // 副表外键字段名 - as:"kehuInfo", // 副表数据插入到主表的字段名 - pageKey:true, // 是否分页(会返回count和hasMore) + foreignKey2:"user_id", // 副表外键字段名 + as:"testList", // 副表数据插入到主表的字段名 + getCount:false, // 是否同时返回总数(会执行count) pageIndex:1, // 当前第几页 pageSize:10, // 每页显示数据 + whereJson:{ // 主表where条件 + + }, + whereJson2:{ // 副表where条件 + + }, fieldJson:{ // 主表字段显示规则 token:false, password:false, @@ -34,13 +40,10 @@ module.exports = { fieldJson2:{ // 副表字段显示规则 }, - whereJson:{ // 主表where条件 + sortArr:[ // 主表排序规则 - }, - whereJson2:{ // 副表where条件 - money:1 - }, - sortArr:[ // 排序规则 + ], + sortArr2:[ // 副表排序规则 { "name":"money", "type":"desc" diff --git a/package-lock.json b/package-lock.json index 0ab21e3..cc37e01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,9 @@ "integrity": "sha512-CpSWQyRlOYkPLOWWhFM5so6Epy3Wp+7HGPg2rGyMaC9kKHEv848a2T7xq6qgZsVjcYZOZwJCMJel7TiZZKNV8w==" }, "vk-unicloud-page": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/vk-unicloud-page/-/vk-unicloud-page-1.10.1.tgz", - "integrity": "sha512-rKU8ePoy5sx1v4H4cOog7JLxbM+7yoA+nzbxdzBqbkNd31WMY1ZzwMVyOP60wVUPmcdvPGWx9o4BV+9s1s6KJg==", + "version": "1.10.4", + "resolved": "https://registry.npmjs.org/vk-unicloud-page/-/vk-unicloud-page-1.10.4.tgz", + "integrity": "sha512-8fkqo3O/N6JeDrsB5mDo9J6gDVe5NklpMf1g8lADT8BDoe9eTlf6lZiXCdZM9ep8xF3Ec8Jn7NfjQIhsiG84KQ==", "requires": { "uview-ui": "~1.7.7" } diff --git a/package.json b/package.json index 73c89cd..2bce40f 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "【开箱即用】vk-uniCloud-router - 云函数路由模式 - uniCloud开发框架 - 已集成uni-id", "main": "main.js", "dependencies": { - "vk-unicloud-page": "^1.10.1" + "vk-unicloud-page": "^1.10.4" }, "devDependencies": {}, "scripts": { -- GitLab