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

宫格页新增根据,当前用户是否登陆、是否为管理员的角色来决定是否显示

上级 5a8dda09
...@@ -375,6 +375,11 @@ uni-starter ...@@ -375,6 +375,11 @@ uni-starter
</pre> </pre>
完整的uni-app目录结构[详情](https://uniapp.dcloud.io/frame?id=%e7%9b%ae%e5%bd%95%e7%bb%93%e6%9e%84) 完整的uni-app目录结构[详情](https://uniapp.dcloud.io/frame?id=%e7%9b%ae%e5%bd%95%e7%bb%93%e6%9e%84)
### 常见API示范
1. 判断当前用户是否拥有某角色`uniIDHasRole` 演示页面:`/pages/grid/grid` [API文档详情:](https://uniapp.dcloud.io/api/global?id=uniidhasrole)
2. 指纹解锁、人脸解锁 演示页面:`/pages/ucenter/settings/settings` [API文档详情:](https://uniapp.dcloud.io/api/system/authentication)
### 注意事项 ### 注意事项
1. 真机运行需要制作自定义基座,制作后选择运行到自定义基座 1. 真机运行需要制作自定义基座,制作后选择运行到自定义基座
2. 苹果登录的图标,需要满足苹果应用市场的审核规范请勿随便修改;如需修改请先阅读:[Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/sign-in-with-apple/overview/buttons/) 2. 苹果登录的图标,需要满足苹果应用市场的审核规范请勿随便修改;如需修改请先阅读:[Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/sign-in-with-apple/overview/buttons/)
......
## 1.0.7(2021-05-22)
删除多余数据
## 1.0.6(2021-05-22)
修复当username(用户名&密码)为第一优先级的登陆方式时。无法切换到smsCode(短信验证码)登陆方式
## 1.0.5(2021-05-20) ## 1.0.5(2021-05-20)
改用uni_modules方式处理图片选择api时无权限,引导用户快捷打开系统设置 改用uni_modules方式处理图片选择api时无权限,引导用户快捷打开系统设置
## 1.0.4(2021-05-19) ## 1.0.4(2021-05-19)
......
<template>
<view v-if="pass">
<slot></slot>
</view>
</template>
<script>
export default {
name:"uni-id-show",
props: {
isLogin:{
type: Boolean,
default(){
return false
}
},
role: {
type: [Array,String],
default(){
return "ALL"
}
},
permission: {
type: [Array,String],
default(){
return "ALL"
}
}
},
data() {
return {
pass: true
}
},
created() {
this.check()
},
methods:{
check(){
let {permission,role,tokenExpired,uid} = uniCloud.getCurrentUserInfo()
console.log(permission,role,tokenExpired,uid);
let pass = true
//1.是否需要登陆
if(this.isLogin){
pass = uid != null
}
//2.角色要求
if(this.role != "ALL"){
pass = role.some(item => this.role.includes(item));
}
//3.权限要求
if(this.permission != "ALL"){
pass = permission.some(item => this.permission.includes(item));
}
this.pass = pass
}
}
}
</script>
\ No newline at end of file
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
return '/' + pages[pages.length - n].route return '/' + pages[pages.length - n].route
}, },
to(path) { to(path) {
console.log('比较', this.getRoute(2), path) // console.log('比较', this.getRoute(2), path)
if (this.getRoute(2) == path) { // 控制路由是重新打开还是返回,避免重复打开页面 if (this.getRoute(2) == path) { // 控制路由是重新打开还是返回,避免重复打开页面
uni.navigateBack(); uni.navigateBack();
} else { } else {
......
{ {
"id": "uni-starter", "id": "uni-starter",
"displayName": "uni-starter", "displayName": "uni-starter",
"version": "1.0.5", "version": "1.0.7",
"description": "云端一体应用快速开发模版", "description": "云端一体应用快速开发模版",
"keywords": [ "keywords": [
"uni-starter", "uni-starter",
......
<template> <template>
<view class="warp"> <view class="warp">
<!-- 搜索 --> <!-- 搜索 -->
<template> <template>
<!-- #ifdef APP-PLUS --> <!-- #ifdef APP-PLUS -->
<status-bar /> <status-bar />
<!-- #endif --> <!-- #endif -->
<uni-search-bar ref="searchBar" style="flex:1;" radius="100" @click.native="searchClick" cancelButton="none" <uni-search-bar ref="searchBar" style="flex:1;" radius="100" @click.native="searchClick" cancelButton="none"
disabled /> disabled />
...@@ -11,22 +11,26 @@ ...@@ -11,22 +11,26 @@
<!-- banner --> <!-- banner -->
<unicloud-db ref="bannerdb" v-slot:default="{data, loading, error, options}" collection="opendb-banner" <unicloud-db ref="bannerdb" v-slot:default="{data, loading, error, options}" collection="opendb-banner"
:field="field" @load="load"> :field="field" @load="load">
<uni-swiper-dot class="uni-swiper-dot-box" @clickItem="clickItem" :info="data || bannerFormate(data, loading)" <uni-swiper-dot class="uni-swiper-dot-box" @clickItem="clickItem"
:current="current" :mode="mode" :dots-styles="dotsStyles" field="content"> :info="data || bannerFormate(data, loading)" :current="current" :mode="mode" :dots-styles="dotsStyles"
field="content">
<swiper class="swiper-box" @change="changeSwiper" :current="swiperDotIndex"> <swiper class="swiper-box" @change="changeSwiper" :current="swiperDotIndex">
<swiper-item v-for="(item, index) in (data || bannerFormate(data, loading))" :key="item._id"> <swiper-item v-for="(item, index) in (data || bannerFormate(data, loading))" :key="item._id">
<view :draggable="false" class="swiper-item" @click="clickBannerItem(item)"> <view :draggable="false" class="swiper-item" @click="clickBannerItem(item)">
<image class="swiper-image" :src="item.bannerfile.url" mode="aspectFill" :draggable="false" /> <image class="swiper-image" :src="item.bannerfile.url" mode="aspectFill"
:draggable="false" />
</view> </view>
</swiper-item> </swiper-item>
</swiper> </swiper>
</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"> <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;"> <view class="grid-item-box" style="background-color: #fff;">
<image :src="item.url" class="image" mode="aspectFill" /> <image :src="item.url" class="image" mode="aspectFill" />
<text class="text">{{ item.text }}</text> <text class="text">{{ item.text }}</text>
...@@ -37,55 +41,76 @@ ...@@ -37,55 +41,76 @@
</view> </view>
</template> </template>
<script> <script>
import {
mapGetters,
} 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 {
components: { statusBar }, components: {
statusBar
},
data() { data() {
return { return {
list: [{ list: [{
url: '/static/grid/c1.png', url: '/static/grid/c1.png',
text: 'Grid 1', text: '所有人可见',
badge: '0', badge: '0',
type: "primary" type: "primary",
isShow: true
}, },
{ {
url: '/static/grid/c2.png', url: '/static/grid/c2.png',
text: 'Grid 2', text: '所有人可见',
badge: '1', badge: '1',
type: "success" type: "success",
}, isShow: true
{ }, {
url: '/static/grid/c3.png', url: '/static/grid/c3.png',
text: 'Grid 3', text: '所有人可见',
badge: '99', badge: '1',
type: "warning" type: "success",
isShow: true
}, },
{ {
url: '/static/grid/c4.png', url: '/static/grid/c4.png',
text: 'Grid 4', text: '游客不可见',
badge: '2', badge: '1',
type: "error" type: "success",
isShow: "this.hasLogin"
}, },
{ {
url: '/static/grid/c5.png', url: '/static/grid/c5.png',
text: 'Grid 5' text: '游客不可见',
badge: '1',
type: "success",
isShow: "hasLogin"
}, },
{ {
url: '/static/grid/c6.png', url: '/static/grid/c6.png',
text: 'Grid 6' text: '游客不可见',
badge: '1',
type: "success",
isShow: "hasLogin"
}, },
{ {
url: '/static/grid/c7.png', url: '/static/grid/c7.png',
text: 'Grid 7' text: '管理员可见',
badge: '99',
type: "warning",
isShow: "uniIDHasPermission('admin')"
}, },
{ {
url: '/static/grid/c8.png', url: '/static/grid/c8.png',
text: 'Grid 8' text: '管理员可见',
badge: '2',
type: "error",
isShow: "uniIDHasPermission('admin')"
}, },
{ {
url: '/static/grid/c9.png', url: '/static/grid/c9.png',
text: 'Grid 9' text: '管理员可见',
isShow: "uniIDHasPermission('admin')"
} }
], ],
// 查询字段,多个字段用 , 分割 // 查询字段,多个字段用 , 分割
...@@ -119,12 +144,16 @@ ...@@ -119,12 +144,16 @@
current: 0, current: 0,
mode: 'default', mode: 'default',
dotsStyles: {}, dotsStyles: {},
swiperDotIndex: 0, swiperDotIndex: 0,
isLoading: true
isLoading:true
} }
}, },
methods: { computed: {
...mapGetters({
hasLogin: 'user/hasLogin'
})
},
methods: {
change(e) { change(e) {
let { let {
index index
...@@ -147,7 +176,7 @@ ...@@ -147,7 +176,7 @@
* banner加载后触发的回调 * banner加载后触发的回调
*/ */
load(data) { load(data) {
}, },
changeSwiper(e) { changeSwiper(e) {
this.current = e.detail.current this.current = e.detail.current
...@@ -170,12 +199,12 @@ ...@@ -170,12 +199,12 @@
*/ */
clickBannerItem(item) { clickBannerItem(item) {
// 有外部链接-跳转url // 有外部链接-跳转url
if (item.open_url) { if (item.open_url) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/common/webview/webview?url='+item.open_url+'&title='+item.title, url: '/pages/common/webview/webview?url=' + item.open_url + '&title=' + item.title,
success: res => {}, success: res => {},
fail: () => {}, fail: () => {},
complete: () => {} complete: () => {}
}); });
} }
// 其余业务处理 // 其余业务处理
...@@ -183,7 +212,7 @@ ...@@ -183,7 +212,7 @@
/** /**
* banner数据过滤 * banner数据过滤
*/ */
bannerFormate(bannerList, loading) { bannerFormate(bannerList, loading) {
if (loading) return []; if (loading) return [];
if (bannerList.length > 0) return bannerList; if (bannerList.length > 0) return bannerList;
// 无数据添加默认值 // 无数据添加默认值
...@@ -201,6 +230,7 @@ ...@@ -201,6 +230,7 @@
<style> <style>
@charset "UTF-8"; @charset "UTF-8";
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
page { page {
display: flex; display: flex;
...@@ -228,12 +258,13 @@ ...@@ -228,12 +258,13 @@
background-color: #ffffff; background-color: #ffffff;
} }
/* #endif */ /* #endif */
/* #ifdef APP-NVUE */ /* #ifdef APP-NVUE */
.warp{ .warp {
background-color: #fff; background-color: #fff;
} }
/* #endif */ /* #endif */
.example-body { .example-body {
...@@ -309,4 +340,4 @@ ...@@ -309,4 +340,4 @@
.uni-input-placeholder { .uni-input-placeholder {
font-size: 28rpx; font-size: 28rpx;
} }
</style> </style>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
// #ifndef APP-NVUE // #ifndef APP-NVUE
this.listHight = 'auto' this.listHight = 'auto'
// #endif // #endif
cdbRef = this.$refs.udb cdbRef = this.$refs.udb
}, },
onShow() { onShow() {
this.keyword = getApp().globalData.searchText this.keyword = getApp().globalData.searchText
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册