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