提交 badab554 编写于 作者: DCloud_JSON's avatar DCloud_JSON

1. 简化宫格页面写法,方便理解如何控制不同状态角色的用户是否可见哪些元素。 2....

1. 简化宫格页面写法,方便理解如何控制不同状态角色的用户是否可见哪些元素。 2. uni-id-cf发送短信验证码api,默认注释掉:虚拟发送短信验证码的代码块。 3. uni-id-cf统一action名称为驼峰法
上级 b70843d1
## 1.0.30(2021-07-01)
1. 简化宫格页面写法,方便理解如何控制不同状态角色的用户是否可见哪些元素。
2. uni-id-cf发送短信验证码api,默认注释掉:虚拟发送短信验证码的代码块。
3. uni-id-cf统一action名称为驼峰法
## 1.0.29(2021-06-29) ## 1.0.29(2021-06-29)
1. 修复在安卓10以下设备,操作登陆获取不到oaid会直接导致登陆失败的bug 1. 修复在安卓10以下设备,操作登陆获取不到oaid会直接导致登陆失败的bug
2. 修复uniCloud版本为阿里云版时删除头像设置失败,腾讯云版删除头像后二次上传失败的问题 2. 修复uniCloud版本为阿里云版时删除头像设置失败,腾讯云版删除头像后二次上传失败的问题
......
...@@ -25,25 +25,28 @@ ...@@ -25,25 +25,28 @@
</uni-swiper-dot> </uni-swiper-dot>
</unicloud-db> </unicloud-db>
<!-- 宫格 --> <!-- 宫格 -->
<uni-section title="宫格组件" style="margin: 0;" type="line"></uni-section> <uni-section title="宫格组件" style="margin: 0;" type="line"></uni-section>
<view class="example-body"> <view class="example-body">
<uni-grid :column="3" :highlight="true" @change="change"> <uni-grid :column="3" :highlight="true" @change="change">
<uni-grid-item v-for="(item, index) in list" :index="index" :key="index" <template v-for="(item,i) in gridList">
v-if="index<3?true:(index<6?hasLogin:uniIDHasRole('admin'))" <uni-grid-item :index="i" :key="i"
> v-if="i<3 || i>3&&i<7&&hasLogin || i>7&&uniIDHasRole('admin')"
<view class="grid-item-box" style="background-color: #fff;"> >
<image :src="item.url" class="image" mode="aspectFill" /> <view class="grid-item-box" style="background-color: #fff;">
<text class="text">{{ item.text }}</text> <image :src="'/static/grid/c'+(i+1)+'.png'" class="image" mode="aspectFill" />
</view> <text class="text">{{item}}</text>
</uni-grid-item> </view>
</uni-grid-item>
</template>
</uni-grid> </uni-grid>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { import {
mapGetters, mapGetters,
} from 'vuex'; } from 'vuex';
import statusBar from "@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-status-bar"; import statusBar from "@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-status-bar";
export default { export default {
...@@ -52,67 +55,7 @@ ...@@ -52,67 +55,7 @@
}, },
data() { data() {
return { return {
list: [{ gridList: ['所有人可见','所有人可见','所有人可见', '游客不可见', '游客不可见', '游客不可见','管理员可见','管理员可见','管理员可见'],
url: '/static/grid/c1.png',
text: '所有人可见',
badge: '0',
type: "primary",
isShow: true
},
{
url: '/static/grid/c2.png',
text: '所有人可见',
badge: '1',
type: "success",
isShow: true
}, {
url: '/static/grid/c3.png',
text: '所有人可见',
badge: '1',
type: "success",
isShow: true
},
{
url: '/static/grid/c4.png',
text: '游客不可见',
badge: '1',
type: "success",
isShow: "this.hasLogin"
},
{
url: '/static/grid/c5.png',
text: '游客不可见',
badge: '1',
type: "success",
isShow: "hasLogin"
},
{
url: '/static/grid/c6.png',
text: '游客不可见',
badge: '1',
type: "success",
isShow: "hasLogin"
},
{
url: '/static/grid/c7.png',
text: '管理员可见',
badge: '99',
type: "warning",
isShow: "uniIDHasPermission('admin')"
},
{
url: '/static/grid/c8.png',
text: '管理员可见',
badge: '2',
type: "error",
isShow: "uniIDHasPermission('admin')"
},
{
url: '/static/grid/c9.png',
text: '管理员可见',
isShow: "uniIDHasPermission('admin')"
}
],
// 查询字段,多个字段用 , 分割 // 查询字段,多个字段用 , 分割
field: '_id,bannerfile,open_url,title', field: '_id,bannerfile,open_url,title',
where: 'category_id==grid', where: 'category_id==grid',
...@@ -145,23 +88,18 @@ ...@@ -145,23 +88,18 @@
mode: 'default', mode: 'default',
dotsStyles: {}, dotsStyles: {},
swiperDotIndex: 0, swiperDotIndex: 0,
isLoading: true isLoading: true
} }
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
hasLogin: 'user/hasLogin' hasLogin: 'user/hasLogin'
}) })
}, },
methods: { methods: {
change(e) { change(e) {
let {
index
} = e.detail
this.list[index].badge && this.list[index].badge++
uni.showToast({ uni.showToast({
title: `点击第${index+1}个宫格`, title: `点击第${e.detail.index}个宫格`,
icon: 'none' icon: 'none'
}) })
}, },
......
...@@ -48,26 +48,26 @@ ...@@ -48,26 +48,26 @@
*/ */
submit() { submit() {
console.log(this.formData); console.log(this.formData);
uniCloud.callFunction({ uniCloud.callFunction({
name:'uni-id-cf', name:'uni-id-cf',
data:{ data:{
action:'bind_mobile_by_sms', action:'bindMobileBySms',
params:{ params:{
"mobile": this.formData.phone, "mobile": this.formData.phone,
"code": this.formData.code "code": this.formData.code
}, },
}, },
success: ({result}) => { success: ({result}) => {
console.log(result); console.log(result);
this.setUserInfo({"mobile":result.mobile}) this.setUserInfo({"mobile":result.mobile})
uni.showToast({ uni.showToast({
title: result.msg, title: result.msg,
icon: 'none' icon: 'none'
}); });
if (result.code === 0) { if (result.code === 0) {
uni.navigateBack() uni.navigateBack()
} }
} }
}) })
} }
} }
......
...@@ -55,13 +55,13 @@ ...@@ -55,13 +55,13 @@
...mapGetters({ ...mapGetters({
userInfo: 'user/info', userInfo: 'user/info',
login: 'user/hasLogin' login: 'user/hasLogin'
}), }),
avatar_file(){ avatar_file(){
if(this.userInfo.avatar_file&&this.userInfo.avatar_file.url){ if(this.userInfo.avatar_file&&this.userInfo.avatar_file.url){
return this.userInfo.avatar_file return this.userInfo.avatar_file
} }
} }
}, },
methods: { methods: {
...mapMutations({ ...mapMutations({
setUserInfo: 'user/login' setUserInfo: 'user/login'
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
uniCloud.callFunction({ uniCloud.callFunction({
name: 'uni-id-cf', name: 'uni-id-cf',
data: { data: {
action: 'bind_mobile_by_univerify', action: 'bindMobileByUniverify',
params: e.authResult, params: e.authResult,
}, },
success: ({ success: ({
...@@ -155,102 +155,102 @@ ...@@ -155,102 +155,102 @@
} else { } else {
this.$refs.dialog.open() this.$refs.dialog.open()
} }
}, },
removeAvatar(){ removeAvatar(){
this.setAvatarFile({ this.setAvatarFile({
"extname": "jpg", "extname": "jpg",
"fileType": "image", "fileType": "image",
"name": "", "name": "",
"size": 0, "size": 0,
"url": "" "url": ""
}) })
}, },
setAvatarFile(avatar_file){ setAvatarFile(avatar_file){
uni.showLoading({ uni.showLoading({
title: '设置中', title: '设置中',
mask: true mask: true
}); });
// 使用 clientDB 提交数据 // 使用 clientDB 提交数据
usersTable.where('_id==$env.uid').update({ usersTable.where('_id==$env.uid').update({
avatar_file avatar_file
}).then((res) => { }).then((res) => {
console.log(res); console.log(res);
if(avatar_file){ if(avatar_file){
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '设置成功' title: '设置成功'
}) })
}else{ }else{
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '删除成功' title: '删除成功'
}) })
} }
this.setUserInfo({ this.setUserInfo({
avatar_file avatar_file
}); });
}).catch((err) => { }).catch((err) => {
uni.showModal({ uni.showModal({
content: err.message || content: err.message ||
'请求服务失败', '请求服务失败',
showCancel: false showCancel: false
}) })
}).finally(() => { }).finally(() => {
uni.hideLoading() uni.hideLoading()
}) })
}, },
uploadAvatarImg(res) { uploadAvatarImg(res) {
const crop = { const crop = {
quality: 100, quality: 100,
width: 600, width: 600,
height: 600, height: 600,
resize: true resize: true
}; };
uni.chooseImage({ uni.chooseImage({
count: 1,crop, count: 1,crop,
success: async (res) => { success: async (res) => {
console.log(res); console.log(res);
let tempFile = res.tempFiles[0], let tempFile = res.tempFiles[0],
avatar_file = { avatar_file = {
// #ifdef H5 // #ifdef H5
extname:tempFile.name.split('.')[tempFile.name.split('.').length-1], extname:tempFile.name.split('.')[tempFile.name.split('.').length-1],
// #endif // #endif
// #ifndef H5 // #ifndef H5
extname:tempFile.path.split('.')[tempFile.path.split('.').length-1] extname:tempFile.path.split('.')[tempFile.path.split('.').length-1]
// #endif // #endif
}, },
filePath = res.tempFilePaths[0] filePath = res.tempFilePaths[0]
// #ifndef APP-PLUS // #ifndef APP-PLUS
//非app端用前端组件剪裁头像,app端用内置的原生裁剪 //非app端用前端组件剪裁头像,app端用内置的原生裁剪
filePath = await new Promise((callback) => { filePath = await new Promise((callback) => {
uni.navigateTo({ uni.navigateTo({
url: '/pages/ucenter/userinfo/cropImage?path=' + filePath + url: '/pages/ucenter/userinfo/cropImage?path=' + filePath +
`&options=${JSON.stringify(crop)}`, `&options=${JSON.stringify(crop)}`,
animationType: "fade-in", animationType: "fade-in",
events: { events: {
success: url=> { success: url=> {
callback(url) callback(url)
} }
} }
}); });
}) })
// #endif // #endif
console.log(this.userInfo); console.log(this.userInfo);
let cloudPath = this.userInfo._id+''+Date.now() let cloudPath = this.userInfo._id+''+Date.now()
avatar_file.name = cloudPath avatar_file.name = cloudPath
uni.showLoading({ uni.showLoading({
title: '正在上传', title: '正在上传',
mask: true mask: true
}); });
let {fileID} = await uniCloud.uploadFile({ let {fileID} = await uniCloud.uploadFile({
filePath,cloudPath, filePath,cloudPath,
fileType:"image" fileType:"image"
}); });
// console.log(result) // console.log(result)
avatar_file.url = fileID avatar_file.url = fileID
console.log({avatar_file}); console.log({avatar_file});
uni.hideLoading() uni.hideLoading()
this.setAvatarFile(avatar_file) this.setAvatarFile(avatar_file)
} }
}) })
...@@ -279,4 +279,4 @@ ...@@ -279,4 +279,4 @@
height: 130rpx; height: 130rpx;
line-height: 130rpx; line-height: 130rpx;
} }
</style> </style>
## 1.0.2(2021-07-01)
1. 发送短信验证码api,默认注释掉:虚拟发送短信验证码的代码块。
2. 统一action名称为驼峰法
## 1.0.1(2021-06-28) ## 1.0.1(2021-06-28)
修复resetPwdBySmsCode接口,未注册过的用户也能调用的问题 修复resetPwdBySmsCode接口,未注册过的用户也能调用的问题
## 1.0.0(2021-06-21) ## 1.0.0(2021-06-21)
......
{ {
"id": "uni-id-cf", "id": "uni-id-cf",
"displayName": "uni-id-cf", "displayName": "uni-id-cf",
"version": "1.0.1", "version": "1.0.2",
"description": "uni-id-cf", "description": "uni-id-cf",
"keywords": [ "keywords": [
"uni-id-cf", "uni-id-cf",
......
...@@ -6,9 +6,9 @@ const uniIdConfig = createConfig({ ...@@ -6,9 +6,9 @@ const uniIdConfig = createConfig({
pluginId: 'uni-id' pluginId: 'uni-id'
}).config() }).config()
const db = uniCloud.database() const db = uniCloud.database()
const dbCmd = db.command const dbCmd = db.command
const usersDB = db.collection('uni-id-users') const usersDB = db.collection('uni-id-users')
exports.main = async (event, context) => { exports.main = async (event, context) => {
//UNI_WYQ:这里的uniID换成新的,保证多人访问不会冲突 //UNI_WYQ:这里的uniID换成新的,保证多人访问不会冲突
uniID = uniID.createInstance({ uniID = uniID.createInstance({
context context
...@@ -22,7 +22,7 @@ exports.main = async (event, context) => { ...@@ -22,7 +22,7 @@ exports.main = async (event, context) => {
*/ */
const { const {
action, action,
uniIdToken, uniIdToken,
inviteCode inviteCode
} = event; } = event;
const deviceInfo = event.deviceInfo || {}; const deviceInfo = event.deviceInfo || {};
...@@ -60,23 +60,23 @@ exports.main = async (event, context) => { ...@@ -60,23 +60,23 @@ exports.main = async (event, context) => {
return payload return payload
} }
params.uid = payload.uid params.uid = payload.uid
} }
//禁止前台用户传递角色 //禁止前台用户传递角色
if (action.slice(0,7) == "loginBy") { if (action.slice(0,7) == "loginBy") {
if (params.role) { if (params.role) {
return { return {
code: 403, code: 403,
msg: '禁止前台用户传递角色' msg: '禁止前台用户传递角色'
} }
} }
} }
//3.注册成功后创建新用户的积分表方法 //3.注册成功后创建新用户的积分表方法
async function registerSuccess(uid) { async function registerSuccess(uid) {
//用户接受邀请 //用户接受邀请
if(inviteCode){ if(inviteCode){
await uniID.acceptInvite({inviteCode,uid}); await uniID.acceptInvite({inviteCode,uid});
} }
//添加当前用户设备信息 //添加当前用户设备信息
await db.collection('uni-id-device').add({ await db.collection('uni-id-device').add({
...@@ -93,9 +93,9 @@ exports.main = async (event, context) => { ...@@ -93,9 +93,9 @@ exports.main = async (event, context) => {
}) })
} }
//4.记录成功登录的日志方法 //4.记录成功登录的日志方法
const loginLog = async (res = {}) => { const loginLog = async (res = {}) => {
if(res.code != 0){ if(res.code != 0){
return false return false
} }
const now = Date.now() const now = Date.now()
const uniIdLogCollection = db.collection('uni-id-log') const uniIdLogCollection = db.collection('uni-id-log')
...@@ -117,7 +117,7 @@ exports.main = async (event, context) => { ...@@ -117,7 +117,7 @@ exports.main = async (event, context) => {
if (res.type == 'register') { if (res.type == 'register') {
await registerSuccess(res.uid) await registerSuccess(res.uid)
} else { } else {
if (Object.keys(deviceInfo).length) { if (Object.keys(deviceInfo).length) {
console.log(979797,{deviceInfo,user_id: res}); console.log(979797,{deviceInfo,user_id: res});
//更新当前用户设备信息 //更新当前用户设备信息
await db.collection('uni-id-device').where({ await db.collection('uni-id-device').where({
...@@ -130,7 +130,7 @@ exports.main = async (event, context) => { ...@@ -130,7 +130,7 @@ exports.main = async (event, context) => {
let res = {} let res = {}
switch (action) { //根据action的值执行对应的操作 switch (action) { //根据action的值执行对应的操作
case 'bind_mobile_by_univerify': case 'bindMobileByUniverify':
let { let {
appid, apiKey, apiSecret appid, apiKey, apiSecret
} = uniIdConfig.service.univerify } = uniIdConfig.service.univerify
...@@ -150,7 +150,7 @@ exports.main = async (event, context) => { ...@@ -150,7 +150,7 @@ exports.main = async (event, context) => {
res.mobile = univerifyRes.phoneNumber res.mobile = univerifyRes.phoneNumber
} }
break; break;
case 'bind_mobile_by_sms': case 'bindMobileBySms':
// console.log({ // console.log({
// uid: params.uid, // uid: params.uid,
// mobile: params.mobile, // mobile: params.mobile,
...@@ -163,7 +163,7 @@ exports.main = async (event, context) => { ...@@ -163,7 +163,7 @@ exports.main = async (event, context) => {
}) })
// console.log(res); // console.log(res);
break; break;
case 'register': case 'register':
var {username, password, nickname} = params var {username, password, nickname} = params
if (/^1\d{10}$/.test(username)) { if (/^1\d{10}$/.test(username)) {
return { return {
...@@ -223,7 +223,7 @@ exports.main = async (event, context) => { ...@@ -223,7 +223,7 @@ exports.main = async (event, context) => {
res.needCaptcha = needCaptcha; res.needCaptcha = needCaptcha;
break; break;
case 'loginByWeixin': case 'loginByWeixin':
res = await uniID.loginByWeixin(params); res = await uniID.loginByWeixin(params);
await uniID.updateUser({ await uniID.updateUser({
uid: res.uid, uid: res.uid,
...@@ -246,13 +246,15 @@ exports.main = async (event, context) => { ...@@ -246,13 +246,15 @@ exports.main = async (event, context) => {
case 'logout': case 'logout':
res = await uniID.logout(uniIdToken) res = await uniID.logout(uniIdToken)
break; break;
case 'sendSmsCode': case 'sendSmsCode':
// 测试期间短信统一用 123456 正式项目删除即可 /* -开始- 测试期间,为节约资源。统一虚拟短信验证码为: 123456;开启以下代码块即可 */
return uniID.setVerifyCode({ // return uniID.setVerifyCode({
mobile: params.mobile, // mobile: params.mobile,
code: '123456', // code: '123456',
type: params.type // type: params.type
}) // })
/* -结束- */
// 简单限制一下客户端调用频率 // 简单限制一下客户端调用频率
const ipLimit = await db.collection('opendb-verify-codes').where({ const ipLimit = await db.collection('opendb-verify-codes').where({
ip: context.CLIENTIP, ip: context.CLIENTIP,
...@@ -308,7 +310,7 @@ exports.main = async (event, context) => { ...@@ -308,7 +310,7 @@ exports.main = async (event, context) => {
code: 500, code: 500,
msg: '手机号码填写错误' msg: '手机号码填写错误'
} }
} }
params.type = 'login' params.type = 'login'
let loginBySmsRes = await uniID.loginBySms(params) let loginBySmsRes = await uniID.loginBySms(params)
// console.log(loginBySmsRes); // console.log(loginBySmsRes);
......
{ {
"name" : "uni-starter", "name" : "uni-starter",
"appid" : "__UNI__E5373F7", "appid" : "__UNI__03B096E",
"description" : "云端一体应用快速开发模版", "description" : "云端一体应用快速开发模版",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册