notice.vue 3.84 KB
<template>
	<view class="bgView">
		<view class="content">
			<!-- <view class="titleView" v-if="videoURL.valueOf().length === 0">
				<view class="title">{{title}}</view>
			</view> -->
			<view class="time" v-if="videoURL.valueOf().length === 0">{{createTime}}</view>
			<video class="videoView" :src="videoURL.valueOf()" v-if="videoURL.valueOf().length > 0"></video>
			<view class="textContent">
				<rich-text class="textView" :nodes="format(text)"></rich-text>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { onLoad,onShow } from '@dcloudio/uni-app'
	import { getCurrentInstance, ref } from 'vue'
	import registerApi from "@/api/register"
	const instance = getCurrentInstance()
	const { proxy } = instance
	
	const videoURL = ref<string>('')
	const text = ref<string>('')
	const title = ref<string>('')
	const createTime = ref<string>('')

	onLoad((options) => {
		requestData()
	})
	onShow(() => {
		
	})
	
	function requestData() {
		registerApi.getNotice({type: 'tos'}).then((res) => {
			console.log('getNotice', res)
			text.value = res.data.noticeContent
			// videoURL.value = res.data.video
			title.value = res.data.noticeTitle
		}).catch((error) => {
			uni.showToast({
				title: error.msg,
				icon: 'none'
			})
		})
	}
	function format(html) {
		var GRT = [
			// img 样式
			['img', "max-width:100%;height:auto;"],
		];
		for (let i = 0; i < GRT.length; i++) {
			html = html.replace(new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi'), function (word) {
				// 分析 dom 上是否带有 style=""
				if (word.indexOf('style=') != -1) {
					var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
					return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
				} else {
					var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
					return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
				}
			});
		}
		return html;
	}
</script>

<style lang="scss" scoped>
	.bgView {
		display: flex;
		position: relative;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 100%;
		background-color: #FFFFFF;

		.footer_wrapper {
			display: flex;
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 10;
			width: 100vw;
			overflow: hidden;
			background: #ffffff;
			height: 160rpx;

			.liuzi {
				display: flex;
				background: #587CF7;
				box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(0, 0, 0, 0.2);
				border-radius: 44rpx;
				margin-left: 16rpx;
				margin-right: 16rpx;
				justify-content: center;
				align-items: center;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 45rpx;
				text-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
				flex: 1;
				height: 88rpx;
				margin-top: 20rpx;
			}
			.disable {
				opacity: 0.5;
			}
		}

		.content {
			display: flex;
			position: relative;
			flex-direction: column;
			align-items: center;
			width: 100%;

			.titleView {
				display: flex;
				position: relative;
				width: 100%;
				margin-top: 20rpx;

				.title {
					display: flex;
					position: relative;
					font-size: 34rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					color: #000000;
					line-height: 48rpx;
					margin-left: 30rpx;
					margin-right: 30rpx;
				}
			}

			.time {

				display: flex;
				position: relative;
				width: 100%;
				font-size: 26rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #6B6D73;
				line-height: 40rpx;
				padding-left: 60rpx;
				margin-top: 20rpx;
			}

			.videoView {
				width: 100%;
				margin-top: 20rpx;
			}

			.textContent {
				margin-top: 40rpx;
				margin-left: 30rpx;
				margin-right: 30rpx;

				.textView {
					font-size: 28rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #222222;
					line-height: 48rpx;
					white-space: pre-wrap;
				}
			}
		}
	}
</style>