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

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

上级 5a8dda09
......@@ -375,6 +375,11 @@ uni-starter
</pre>
完整的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. 真机运行需要制作自定义基座,制作后选择运行到自定义基座
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)
改用uni_modules方式处理图片选择api时无权限,引导用户快捷打开系统设置
## 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 @@
return '/' + pages[pages.length - n].route
},
to(path) {
console.log('比较', this.getRoute(2), path)
// console.log('比较', this.getRoute(2), path)
if (this.getRoute(2) == path) { // 控制路由是重新打开还是返回,避免重复打开页面
uni.navigateBack();
} else {
......
{
"id": "uni-starter",
"displayName": "uni-starter",
"version": "1.0.5",
"version": "1.0.7",
"description": "云端一体应用快速开发模版",
"keywords": [
"uni-starter",
......
<template>
<view class="warp">
<!-- 搜索 -->
<template>
<!-- #ifdef APP-PLUS -->
<status-bar />
<template>
<!-- #ifdef APP-PLUS -->
<status-bar />
<!-- #endif -->
<uni-search-bar ref="searchBar" style="flex:1;" radius="100" @click.native="searchClick" cancelButton="none"
disabled />
......@@ -11,22 +11,26 @@
<!-- banner -->
<unicloud-db ref="bannerdb" v-slot:default="{data, loading, error, options}" collection="opendb-banner"
:field="field" @load="load">
<uni-swiper-dot class="uni-swiper-dot-box" @clickItem="clickItem" :info="data || bannerFormate(data, loading)"
:current="current" :mode="mode" :dots-styles="dotsStyles" field="content">
<uni-swiper-dot class="uni-swiper-dot-box" @clickItem="clickItem"
:info="data || bannerFormate(data, loading)" :current="current" :mode="mode" :dots-styles="dotsStyles"
field="content">
<swiper class="swiper-box" @change="changeSwiper" :current="swiperDotIndex">
<swiper-item v-for="(item, index) in (data || bannerFormate(data, loading))" :key="item._id">
<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>
</swiper-item>
</swiper>
</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">
<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>
......@@ -37,55 +41,76 @@
</view>
</template>
<script>
<script>
import {
mapGetters,
} from 'vuex';
import statusBar from "@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-status-bar";
export default {
components: { statusBar },
components: {
statusBar
},
data() {
return {
list: [{
url: '/static/grid/c1.png',
text: 'Grid 1',
text: '所有人可见',
badge: '0',
type: "primary"
type: "primary",
isShow: true
},
{
url: '/static/grid/c2.png',
text: 'Grid 2',
text: '所有人可见',
badge: '1',
type: "success"
},
{
type: "success",
isShow: true
}, {
url: '/static/grid/c3.png',
text: 'Grid 3',
badge: '99',
type: "warning"
text: '所有人可见',
badge: '1',
type: "success",
isShow: true
},
{
url: '/static/grid/c4.png',
text: 'Grid 4',
badge: '2',
type: "error"
text: '游客不可见',
badge: '1',
type: "success",
isShow: "this.hasLogin"
},
{
url: '/static/grid/c5.png',
text: 'Grid 5'
text: '游客不可见',
badge: '1',
type: "success",
isShow: "hasLogin"
},
{
url: '/static/grid/c6.png',
text: 'Grid 6'
text: '游客不可见',
badge: '1',
type: "success",
isShow: "hasLogin"
},
{
url: '/static/grid/c7.png',
text: 'Grid 7'
text: '管理员可见',
badge: '99',
type: "warning",
isShow: "uniIDHasPermission('admin')"
},
{
url: '/static/grid/c8.png',
text: 'Grid 8'
text: '管理员可见',
badge: '2',
type: "error",
isShow: "uniIDHasPermission('admin')"
},
{
url: '/static/grid/c9.png',
text: 'Grid 9'
text: '管理员可见',
isShow: "uniIDHasPermission('admin')"
}
],
// 查询字段,多个字段用 , 分割
......@@ -119,12 +144,16 @@
current: 0,
mode: 'default',
dotsStyles: {},
swiperDotIndex: 0,
isLoading:true
swiperDotIndex: 0,
isLoading: true
}
},
methods: {
computed: {
...mapGetters({
hasLogin: 'user/hasLogin'
})
},
methods: {
change(e) {
let {
index
......@@ -147,7 +176,7 @@
* banner加载后触发的回调
*/
load(data) {
},
changeSwiper(e) {
this.current = e.detail.current
......@@ -170,12 +199,12 @@
*/
clickBannerItem(item) {
// 有外部链接-跳转url
if (item.open_url) {
uni.navigateTo({
url: '/pages/common/webview/webview?url='+item.open_url+'&title='+item.title,
success: res => {},
fail: () => {},
complete: () => {}
if (item.open_url) {
uni.navigateTo({
url: '/pages/common/webview/webview?url=' + item.open_url + '&title=' + item.title,
success: res => {},
fail: () => {},
complete: () => {}
});
}
// 其余业务处理
......@@ -183,7 +212,7 @@
/**
* banner数据过滤
*/
bannerFormate(bannerList, loading) {
bannerFormate(bannerList, loading) {
if (loading) return [];
if (bannerList.length > 0) return bannerList;
// 无数据添加默认值
......@@ -201,6 +230,7 @@
<style>
@charset "UTF-8";
/* #ifndef APP-NVUE */
page {
display: flex;
......@@ -228,12 +258,13 @@
background-color: #ffffff;
}
/* #endif */
/* #ifdef APP-NVUE */
.warp{
background-color: #fff;
}
/* #endif */
/* #ifdef APP-NVUE */
.warp {
background-color: #fff;
}
/* #endif */
.example-body {
......@@ -309,4 +340,4 @@
.uni-input-placeholder {
font-size: 28rpx;
}
</style>
</style>
......@@ -65,7 +65,7 @@
// #ifndef APP-NVUE
this.listHight = 'auto'
// #endif
cdbRef = this.$refs.udb
cdbRef = this.$refs.udb
},
onShow() {
this.keyword = getApp().globalData.searchText
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册