alertCode.vue 2.0 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
<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) {
20
		codes = JSON.parse(JSON.stringify(codes))
study夏羽's avatar
study夏羽 已提交
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
		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) {
50 51 52 53 54 55 56 57 58 59
        if('errCode' in codes){
          // 为过滤警告,不在弹出请求返回的code message
          try{
            delete codes.code
            delete codes.message
            delete codes.affectedDocs
          }catch(e){
            // console.log(e);
          }
        }
study夏羽's avatar
study夏羽 已提交
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 91 92 93 94 95 96 97 98 99 100
				this.codes = purifyCodes(codes)
				this.isShow = true
			},
			tapCode(e) {
				console.log(e);
				e.stopPropagation()
			},
			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>