login-ikonw.vue 1.5 KB
Newer Older
芊里 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
<template>
	<view class="flex flex-row flex-wrap">
		<text class="text-sub font-26" v-for="(t, i) in innerText" :key="i" :class="t.to?'link-color':''"
			@click="clickLink(t)">{{t.text || t}}</text>
	</view>
</template>

<script>
	/**
	 * text 政策描述文字
	 * link 高亮关键字及其链接
	 */
	export default {
		name: "login-ikonw",
		props: {
			text: {
				type: String,
				default: ''
			},
			link: {
				type: Array,
				default: []
			}
		},
		data() {
			return {

			};
		},
		computed: {
			innerText() {
				if (this.link.length == 0) return this.text;
				let textList = String(this.text);
				this.link.forEach(item => {
					textList = textList.replace(item.text, '$');
				});
				textList = textList.split('');
				let list = [],
					linkList = JSON.parse(JSON.stringify(this.link));
				textList.forEach((text, tIndex) => {
					if (text == '$') {
						let currLink = linkList.shift();
						currLink.text.split('').forEach(item => {
							list.push({
								text: item,
								to: currLink.to
							});
						})
					} else {
						list.push({
							text
						})
					}
				});
				return list;
			}
		},
		methods: {
			/**
			 * 点击跳转到协议页面
			 * @param {Object} link
			 */
			clickLink(link) {
				uni.navigateTo({
					url: link.to
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/myStyle.css");

	.link-color {
		color: #04498c;
	}
</style>