常见的功能

手机号脱敏(适用vue语法)

计算总价

关闭广告弹窗,今天不再弹出
<template>
	<view class="content">

		<!-- 协议弹出层 -->
		<uni-popup ref="popup1" type="bottom">
			<view class="xie_pop">
				<view class="xie_content">
					<view class="xie_title">
						顺丰隐私政策概要
					</view>
					<view class="xie_text">
						亲爱的用户,感谢您一直以来的支持!为了更好地保护您的权益,同时遵循相关监管要求,请认真阅读顺丰速运隐私政策,特向您说明如下:
					</view>
					<view class="xie_item" v-for="(item,index) in title">
						{{index+1}}.{{item.title}}
					</view>
				</view>
				<view class="agrees">
					<!-- <navigator class="noagree" open-type="exit" target="miniProgram" @click="noagree">不同意</navigator> -->
					<view class="noagree" @click="noagree">不同意</view>
					<view class="agree" @click="agree">同意</view>
				</view>

			</view>
		</uni-popup>
		<!-- 广告弹出层 -->
		<uni-popup ref="popup2" type="center">
			<view class="pop2">
				<image src="../../static/logo.png" mode=""></image>
			</view>
			<view class="guan" @click="close2">X</view>
		</uni-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				title: [],
			}
		},
		onLoad() {
			//弹出协议弹框
			this.$refs.popup1.open('bottom')
			this.getlist()
			//页面加载完成5秒不动,自动关闭弹窗
			setTimeout(() => {
				this.$refs.popup2.close();
			}, 5000)
		},
		methods: {
			//请求隐私协议的数据
			getlist() {
				uniCloud.callFunction({
					name: 'getlist'
				}).then(res => {
					console.log(res)
					this.title = res.result.data;
					console.log(this.title)
				})
			},
			//同意协议关闭弹出层
			agree() {
				this.$refs.popup1.close();
				取出第一次关闭广告弹窗存到本地的时间, 作出判断今天的弹窗是否再弹出
				let now = +new Date
				let start = uni.getStorageSync('starttime')
				let end = uni.getStorageSync('endtime')
				if (now >= start && now <= end) {
					return
				} else {
					this.$refs.popup2.open('center')
				}
			},
			//不同意退出应用
			noagree() {
				uni.exitMiniProgram({
					complete(res) {
						console.log(res)
					}
				})
			},
			close2() {
				let now = +new Date
				let start = new Date
				start.setHours(0)
				start.setMinutes(0)
				start.setSeconds(0)
				start.setMilliseconds(0)
				start = start.getTime()
				let end = new Date
				end.setHours(23)
				end.setMinutes(59)
				end.setSeconds(59)
				end.setMilliseconds(999)
				uni.setStorageSync('starttime', start)
				uni.setStorageSync('endtime', end)
				//关闭广告弹框
				this.$refs.popup2.close();
			}
		}
	}
</script>
点击不同意协议退出该应用

	noagree() {
				uni.exitMiniProgram({
					complete(res) {
						console.log(res)
					}
				})
			},

uniapp中用 uView写tab切换

页面显示当前时间
<template>
	<view>
		<view class="cur">
			{{currentTime}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentTime: '',
			}
		},
		created() {
			this.getcurrentTime();
			setInterval(() => {
				this.getcurrentTime()
			}, 1000)
		},
		methods: {
			getcurrentTime() {
				const now = new Date();
				const year = now.getFullYear();
				const month = now.getMonth() + 1;
				const day = now.getDate()
				const hour = now.getHours();
				const minute = now.getMinutes();
				const second = now.getSeconds();
				this.currentTime = `${year}年${month}月${day}日  ${hour}:${minute}:${second}`
			}
		}
	}
</script>
当一个页面有多条协议都需要同意,如果有多条不同意那么就无法登录或者是进入其他的页面
<view class="xie">
			<checkbox-group name="" @change="allcheck">
				<label>
					<checkbox value="actived" />
					<text>我已认真阅读并同意以下协议</text>
					<view>《中国建设银行个人信息保护政策》</view>
				</label>
				<label>
					<checkbox value="actived" />
					<text>我已认真阅读并同意以下协议</text>
					<view>《中国建设银行微信金融服务账户绑定协议》</view>
				</label>
				<label>
					<checkbox value="actived" />
					<text>我已认真阅读并同意以下协议</text>
					<view>《中国建设银行微信金融服务个人信息授权书》</view>
				</label>
				<label>
					<checkbox value="actived" />
					<text>同时开通手机银行相关功能及服务</text>
				</label>
			</checkbox-group>
		</view>
		<!-- button 授权认证-->
		<view :class="[actived===true?'active':'login_btn']" @click="login">
			中国建设银行公众号授权认证
		</view>
<script>
	export default {
		data() {
			return {
				actived: false,
				act: 0,
			}
		},
		methods: {
			allcheck(e) {
				if (e.detail.value.length === 4) {
					this.actived = true
					this.act = 1
				} else {
					this.actived = false
					this.act = 0
				}
			},
			login() {
				if (this.act === 1) {
					uni.login({
						success: (res) => {
							console.log(res)
							uni.setStorageSync('code', res.code)
						},
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}, 2000)

				} else {
					uni.showToast({
						title: '需要同意协议'
					})
				}
			}

		}
	}
</script>
无感登录

安装 npm i    js-cookie

登录页面

import Cookies  from 'js-cookie';
import { login } from '../../Api/login/login';
import { reactive } from 'vue'
import { ElMessage } from 'element-plus';
import { useRouter } from 'vue-router';
let router = useRouter();
const form = reactive({
    name: '',
    password: '',
})
const onSubmit = async () => {
    let name = form.name;
    let password = form.password;
    let res = await login({ name, password });
    console.log(res, 1234543212345543)
    if (res.data.msg == 'ok') {
        var date=new Date();
        //2个小时有效期  expiress 后面也可以跟数字,数字代表天数
        var expires=date.getTime()+2*60*60*1000;
        Cookies.set('token',res.data.token,{expires:expires})
        ElMessage({
            message: '登录成功',
            type: 'success',
        })
        router.push('/home/touq')
    } else {
        ElMessage({
            message: '登录失败,账号或密码有误',
            type: 'warning',
        })
    }
}

router.ts

导入    import Cookies from 'js-cookie';

前置守卫

router.beforeEach((to, from, next) => {
  if (to.fullPath !== '/login') {
    if (!Cookies.get('token')) {
      router.push('/login');
      return
    } else {
      next()
    }
  } else {
    next()
  }
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值