alertCode.vue 1.7 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
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 79 80 81 82 83 84 85 86 87 88 89 90
<template>
	<!-- #ifdef MP -->
	<view class="box isShow" @click="closeMe" v-if="isShow">
		<!-- #endif -->
		<!-- #ifndef MP -->
		<view class="box" @click="closeMe" :class="{isShow:isShow}">
			<!-- #endif -->
			<!-- 小程序存在动画切换的bug本版本先用 v-if="isShow" 处理 -->
			<scroll-view scroll-x scroll-y @click.stop="tapCode" class="scroll-view" style="overflow: auto;">
				<show-code :codes="codes"></show-code>
			</scroll-view>
		</view>
</template>
<script>
	function getType(val) {
		return Object.prototype.toString.call(val).slice(8, -1).toLowerCase()
	}

	function purifyCodes(codes) {
		const codesType = getType(codes)
		switch (codesType) {
			case 'object':
				if ('affectedDocs' in codes) {
					delete codes.affectedDocs
				}
				for (let key in codes) {
					codes[key] = purifyCodes(codes[key])
				}
				break;
			case 'array':
				for (let i = 0; i < codes.length; i++) {
					codes[i] = purifyCodes(codes[i])
				}
				break;
			default:
				return codes
		}
		return codes
	}
	export default {
		data() {
			return {
				codes: {},
				isShow: false
			}
		},
		methods: {
			open(codes) {
				this.codes = purifyCodes(codes)
				this.isShow = true
			},
			tapCode(e) {
				console.log(e);
				e.stopPropagation()
			},
			closeMe(e) {
				console.log('closeMe', e);
				this.isShow = false
			}
		}
	}
</script>
<style scoped>
	.box {
		width: 100vw;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.2);
		position: fixed;
		top: 0;
		left: 100vw;
		z-index: 999;
		opacity: 0;
		transition: opacity 0.3s;
		justify-content: center;
		align-items: center;
		display: flex;
	}

	.scroll-view {
		background-color: #FFFAE7;
		padding: 14px 18rpx;
		width: 610rpx;
		max-height: 60vh;
	}

	.isShow {
		opacity: 1;
		left: 0;
	}
</style>