提交 a517c7a0 编写于 作者: d-u-a's avatar d-u-a

feat: 新增安全网络示例

上级 81d683f0
<script> <script>
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
export default { export default {
onLaunch: function() { onLaunch: async function() {
console.log('App Launch') console.log('App Launch')
checkUpdate()//更新升级 checkUpdate() //更新升级
}, },
mounted() { mounted() {
// #ifdef H5 // #ifdef H5
//const VConsole = require('@/common/js/vconsole.min.js') //const VConsole = require('@/common/js/vconsole.min.js')
//new VConsole() //new VConsole()
// #endif // #endif
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
}, },
onHide: function() { onHide: function() {
console.log('App Hide') console.log('App Hide')
} }
} }
</script> </script>
<style> <style>
/*每个页面公共css */ /*每个页面公共css */
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
view{ view {
box-sizing: border-box; box-sizing: border-box;
} }
@font-face {
font-family: "iconfont"; @font-face {
src: url('https://at.alicdn.com/t/font_2354462_s00xh8caffp.ttf'); font-family: "iconfont";
} src: url('https://at.alicdn.com/t/font_2354462_s00xh8caffp.ttf');
.ico{ }
font-family: iconfont;
} .ico {
/* #endif */ font-family: iconfont;
}
/* #endif */
</style> </style>
{ {
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{ {
"path": "pages/cloudFunction/cloudFunction", "path": "pages/cloudFunction/cloudFunction",
"style": { "style": {
"navigationBarTitleText": "云函数", "navigationBarTitleText": "云函数",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/cloudObject/cloudObject", "path": "pages/cloudObject/cloudObject",
"style": { "style": {
"navigationBarTitleText": "云对象", "navigationBarTitleText": "云对象",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/test/test", "path": "pages/secure-network/cloud-function",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "安全网络 - 云函数",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/unicloud-db-demo/unicloud-db-demo", "path": "pages/secure-network/cloud-object",
"style": { "style": {
"navigationBarTitleText": "unicloud-db demo", "navigationBarTitleText": "安全网络 - 云对象",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/demo/demo", "path": "pages/test/test",
"style": { "style": {
"navigationBarTitleText": "留言板", "navigationBarTitleText": "",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/permission-table-simple/permission-table-simple", "path": "pages/clientDB/unicloud-db-demo/unicloud-db-demo",
"style": { "style": {
"navigationBarTitleText": "表级-简单权限控制", "navigationBarTitleText": "unicloud-db demo",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/permission-table-compound/permission-table-compound", "path": "pages/clientDB/demo/demo",
"style": { "style": {
"navigationBarTitleText": "表级-复杂权限控制", "navigationBarTitleText": "留言板",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},
{
"path": "pages/clientDB/permission-table-simple/permission-table-simple",
"style": {
"navigationBarTitleText": "表级-简单权限控制",
"enablePullDownRefresh": false
}
},
{
"path": "pages/clientDB/permission-table-compound/permission-table-compound",
"style": {
"navigationBarTitleText": "表级-复杂权限控制",
"enablePullDownRefresh": false
}
}, },
{ {
"path": "pages/clientDB/clientDB", "path": "pages/clientDB/clientDB",
"style": { "style": {
"navigationBarTitleText": "前端操作数据库", "navigationBarTitleText": "前端操作数据库",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/user-info/add", "path": "pages/user-info/add",
"style": { "style": {
"navigationBarTitleText": "新增" "navigationBarTitleText": "新增"
} }
}, { }, {
"path": "pages/user-info/edit", "path": "pages/user-info/edit",
"style": { "style": {
"navigationBarTitleText": "修改" "navigationBarTitleText": "修改"
} }
}, { }, {
"path": "pages/user-info/list", "path": "pages/user-info/list",
"style": { "style": {
"navigationBarTitleText": "列表" "navigationBarTitleText": "列表"
} }
}, { }, {
"path": "pages/user-info/detail", "path": "pages/user-info/detail",
"style": { "style": {
"navigationBarTitleText": "详情" "navigationBarTitleText": "详情"
} }
}, },
{ {
"path": "pages/storage/storage", "path": "pages/storage/storage",
"style": { "style": {
"navigationBarTitleText": "云存储", "navigationBarTitleText": "云存储",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/schema2code/schema2code", "path": "pages/schema2code/schema2code",
"style": { "style": {
"navigationBarTitleText": "schema2code", "navigationBarTitleText": "schema2code",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/permission/permission", "path": "pages/clientDB/permission/permission",
"style": { "style": {
"navigationBarTitleText": "角色权限", "navigationBarTitleText": "角色权限",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/permission-demo/permission-demo", "path": "pages/clientDB/permission-demo/permission-demo",
"style": { "style": {
"navigationBarTitleText": "角色权限", "navigationBarTitleText": "角色权限",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/permission-demo/readme", "path": "pages/clientDB/permission-demo/readme",
"style": { "style": {
"navigationBarTitleText": "角色权限", "navigationBarTitleText": "角色权限",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/permission-field-simple/permission-field-simple", "path": "pages/clientDB/permission-field-simple/permission-field-simple",
"style": { "style": {
"navigationBarTitleText": "简单-字段级权限控制", "navigationBarTitleText": "简单-字段级权限控制",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/clientDB-api/clientDB-api", "path": "pages/clientDB/clientDB-api/clientDB-api",
"style": { "style": {
"navigationBarTitleText": "前端操作数据库的API", "navigationBarTitleText": "前端操作数据库的API",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/clientDB/validate/validate", "path": "pages/clientDB/validate/validate",
"style": { "style": {
"navigationBarTitleText": "字段值域验证", "navigationBarTitleText": "字段值域验证",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/validate-demo/add", "path": "pages/validate-demo/add",
"style": { "style": {
"navigationBarTitleText": "新增" "navigationBarTitleText": "新增"
} }
}, { }, {
"path": "pages/validate-demo/edit", "path": "pages/validate-demo/edit",
"style": { "style": {
"navigationBarTitleText": "修改" "navigationBarTitleText": "修改"
} }
}, { }, {
"path": "pages/validate-demo/list", "path": "pages/validate-demo/list",
"style": { "style": {
"navigationBarTitleText": "" "navigationBarTitleText": ""
} }
}, { }, {
"path": "pages/validate-demo/detail", "path": "pages/validate-demo/detail",
"style": {} "style": {}
}, { }, {
"path": "pages/webview/webview", "path": "pages/webview/webview",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "uni_modules/uni-upgrade-center-app/pages/upgrade-popup", "path": "uni_modules/uni-upgrade-center-app/pages/upgrade-popup",
"style": { "style": {
"disableScroll": true, "disableScroll": true,
"app-plus": { "app-plus": {
"backgroundColorTop": "transparent", "backgroundColorTop": "transparent",
"background": "transparent", "background": "transparent",
"titleNView": false, "titleNView": false,
"scrollIndicator": false, "scrollIndicator": false,
"popGesture": "none", "popGesture": "none",
"animationType": "fade-in", "animationType": "fade-in",
"animationDuration": 200 "animationDuration": 200
} }
} }
}, { }, {
"path": "pages/cloudFunction/redis/redis", "path": "pages/cloudFunction/redis/redis",
"style": { "style": {
"navigationBarTitleText": "扩展能力Redis", "navigationBarTitleText": "扩展能力Redis",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
} }, {
,{ "path": "uni_modules/uni-upgrade-center/pages/version/list",
"path": "uni_modules/uni-upgrade-center/pages/version/list", "style": {
"style": {
"navigationBarTitleText": "版本列表" "navigationBarTitleText": "版本列表"
} }
} }, {
,{ "path": "uni_modules/uni-upgrade-center/pages/version/add",
"path": "uni_modules/uni-upgrade-center/pages/version/add", "style": {
"style": {
"navigationBarTitleText": "新版发布" "navigationBarTitleText": "新版发布"
} }
} }, {
,{ "path": "uni_modules/uni-upgrade-center/pages/version/detail",
"path": "uni_modules/uni-upgrade-center/pages/version/detail", "style": {
"style": {
"navigationBarTitleText": "版本信息查看" "navigationBarTitleText": "版本信息查看"
}
} }
} ],
], "tabBar": {
"tabBar": { "color": "#7A7E83",
"color": "#7A7E83", "selectedColor": "#1296db",
"selectedColor": "#1296db", "borderStyle": "black",
"borderStyle": "black", "backgroundColor": "#ffffff",
"backgroundColor": "#ffffff", "list": [{
"list": [{ "pagePath": "pages/cloudFunction/cloudFunction",
"pagePath": "pages/cloudFunction/cloudFunction", "iconPath": "static/tabbar/fn.png",
"iconPath": "static/tabbar/fn.png", "selectedIconPath": "static/tabbar/fn1.png",
"selectedIconPath": "static/tabbar/fn1.png", "text": "云函数"
"text": "云函数" },
}, {
{ "pagePath": "pages/cloudObject/cloudObject",
"pagePath": "pages/cloudObject/cloudObject", "iconPath": "static/tabbar/obj.png",
"iconPath": "static/tabbar/obj.png", "selectedIconPath": "static/tabbar/obj1.png",
"selectedIconPath": "static/tabbar/obj1.png", "text": "云对象"
"text": "云对象" },
}, {
{ "pagePath": "pages/storage/storage",
"pagePath": "pages/storage/storage", "iconPath": "static/tabbar/storage.png",
"iconPath": "static/tabbar/storage.png", "selectedIconPath": "static/tabbar/storage1.png",
"selectedIconPath": "static/tabbar/storage1.png", "text": "云存储"
"text": "云存储" },
}, {
{ "pagePath": "pages/clientDB/clientDB",
"pagePath": "pages/clientDB/clientDB", "iconPath": "static/tabbar/yun.png",
"iconPath": "static/tabbar/yun.png", "selectedIconPath": "static/tabbar/yun1.png",
"selectedIconPath": "static/tabbar/yun1.png", "text": "clientDB"
"text": "clientDB" }, {
}, { "pagePath": "pages/schema2code/schema2code",
"pagePath": "pages/schema2code/schema2code", "iconPath": "/static/tabbar/st-code.png",
"iconPath": "/static/tabbar/st-code.png", "selectedIconPath": "static/tabbar/st-code1.png",
"selectedIconPath": "static/tabbar/st-code1.png", "text": "schema2code"
"text": "schema2code" }
} ]
] },
}, "globalStyle": {
"globalStyle": { "navigationBarTextStyle": "black",
"navigationBarTextStyle": "black", "navigationBarTitleText": "uni-app",
"navigationBarTitleText": "uni-app", "navigationBarBackgroundColor": "#F8F8F8",
"navigationBarBackgroundColor": "#F8F8F8", "backgroundColor": "#F8F8F8"
"backgroundColor": "#F8F8F8" }
}
} }
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
<button type="primary" @click="get">查询前10条数据</button> <button type="primary" @click="get">查询前10条数据</button>
<button type="primary" @click="useCommon">使用公用模块</button> <button type="primary" @click="useCommon">使用公用模块</button>
<button type="primary" @click="toRedisPage">使用Redis</button> <button type="primary" @click="toRedisPage">使用Redis</button>
<!-- #ifdef APP-PLUS || MP-WEIXIN -->
<navigator url="../secure-network/cloud-function">
<button type="primary">安全网络</button>
</navigator>
<!-- #endif -->
</view> </view>
</view> </view>
</template> </template>
......
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
<button type="primary" @click="update">修改数据</button> <button type="primary" @click="update">修改数据</button>
<button type="primary" @click="get">查询前10条数据</button> <button type="primary" @click="get">查询前10条数据</button>
<button type="primary" @click="useCommon">使用公用模块</button> <button type="primary" @click="useCommon">使用公用模块</button>
<!-- #ifdef APP-PLUS || MP-WEIXIN -->
<navigator url="../secure-network/cloud-object">
<button type="primary">安全网络</button>
</navigator>
<!-- #endif -->
</view> </view>
</template> </template>
<template v-else> <template v-else>
......
<template>
<view class="container">
<view class="title">请求数据</view>
<input class="input" v-model="inputValue" />
<view class="group">
<view class="secret-type">
secretType: "both"
</view>
<view class="secret-type-comment">
客户端和服务器上行下行数据都加密数据
</view>
<button type="primary" @click="getBySecretType('both')">get</button>
</view>
<view class="group">
<view class="secret-type">
secretType: "request"
</view>
<view class="secret-type-comment">
只加密客户端请求时的上行数据,服务器下发数据不加密
</view>
<button type="primary" @click="getBySecretType('request')">get</button>
</view>
<view class="group">
<view class="secret-type">
secretType: "response"
</view>
<view class="secret-type-comment">
客户端请求时不加密数据,只加密服务器下发的数据
</view>
<button type="primary" @click="getBySecretType('response')">get</button>
</view>
<view class="tips">
提示:
<view class="tips-item">
当前请求的云函数强制校验 secretType: "both",返回值为请求的数据
</view>
<view class="tips-item">
不管是客户端接收云端数据、还是云端接受客户端数据,开发者的代码拿到的数据永远都是解密后的数据
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
inputValue: 'uniCloud-secure-network'
}
},
methods: {
getBySecretType(secretType) {
uni.showLoading({
title: '处理中...'
})
uniCloud.callFunction({
name: 'secure-network',
data: {
value: this.inputValue
},
secretType,
success: (res) => {
uni.showModal({
content: res.result.value,
showCancel: false
})
},
fail: (err) => {
uni.showModal({
content: err.message,
showCancel: false
})
console.error(err)
},
complete: () => {
uni.hideLoading()
}
})
}
}
}
</script>
<style>
@import url("css.css");
</style>
<template>
<view class="container">
<view class="title">请求数据</view>
<input class="input" v-model="inputValue" />
<view class="group">
<view class="secret-type">
secretType: "both"
</view>
<view class="secret-type-comment">
客户端和服务器上行下行数据都加密数据
</view>
<button type="primary" @click="getBySecretType('both')">get</button>
</view>
<view class="group">
<view class="secret-type">
secretType: "request"
</view>
<view class="secret-type-comment">
只加密客户端请求时的上行数据,服务器下发数据不加密
</view>
<button type="primary" @click="getBySecretType('request')">get</button>
</view>
<view class="group">
<view class="secret-type">
secretType: "response"
</view>
<view class="secret-type-comment">
客户端请求时不加密数据,只加密服务器下发的数据
</view>
<button type="primary" @click="getBySecretType('response')">get</button>
</view>
<view class="tips">
提示:
<view class="tips-item">
当前请求的云对象强制校验 secretType: "both",返回值为请求的数据
</view>
<view class="tips-item">
不管是客户端接收云端数据、还是云端接受客户端数据,开发者的代码拿到的数据永远都是解密后的数据
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
inputValue: 'uniCloud-secure-network'
}
},
methods: {
getBySecretType(secretType) {
uni.showLoading({
title: '处理中...'
})
const secureNetworkObject = uniCloud.importObject('secure-network-object', {
secretMethods: {
'get': secretType
}
});
secureNetworkObject.get(this.inputValue).then((res) => {
uni.hideLoading()
uni.showModal({
content: JSON.stringify(res),
showCancel: false
})
}).catch((err) => {
uni.hideLoading()
console.error(err)
})
}
}
}
</script>
<style>
@import url("css.css");
</style>
.container {
padding: 15px;
}
.title {
font-size: 15px;
}
.input {
margin-top: 5px;
padding: 5px 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
.group {
margin-top: 30px;
}
.secret-type {
font-weight: bold;
}
.secret-type-comment {
font-size: 14px;
margin-top: 5px;
opacity: .7;
}
button {
margin-top: 10px;
}
.tips {
font-size: 14px;
margin-top: 30px;
opacity: .8;
}
.tips-item {
display: list-item;
margin-left: 20px;
margin-top: 5px;
}
// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程:https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
_before: function() { // 通用预处理器
const methodName = this.getMethodName()
const clientInfo = this.getClientInfo()
const secretType = clientInfo.secretType
// methodName 是客户端调用的方法名
// secretType 是客户端调用 uniCloud.importObject 传递的参数 secretMethods
console.log(secretType);
if (methodName === 'get' && (secretType !== 'both' || secretType !== 'response')) {
throw new Error('secretType invalid') // 拒绝返回有效数据
}
},
/**
* method1方法描述
* @param {string} param1 参数1描述
* @returns {object} 返回值描述
*/
get(param1) {
// 参数校验,如无参数则不需要
if (!param1) {
return {
errCode: 'PARAM_IS_NULL',
errMsg: '参数不能为空'
}
}
// 业务逻辑
// 返回结果
return {
param1 //请根据实际需要返回值
}
}
}
{
"name": "secure-object",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
const secretType = context.secretType
// secretType 是客户端调用 uniCloud.callFunction 传递的参数 secretType
if (secretType !== 'both' || secretType !== 'response') {
throw new Error('secretType invalid') // 拒绝返回有效数据
}
//返回数据给客户端
return event
};
{
"name": "secure-network",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册