<template>
	<view class="_dbg" @tap.stop="showdbglist" v-if="bshow && me.id>0 && me.dbg">
		<view class="_dbgbg">
		</view>
		<view class="_dbgtxt">
			{{me.id}}<br />
			{{me.name}}
		</view>
	</view>
</template>

<style scoped>
	._dbg {
		top: 10em;
		left: 1em;
		position: fixed;
		width: 4em;
		height: 4em;
		z-index: 10000000;
	}

	._dbgbg {
		position: relative;
		background: #9412cc;
		width: 100%;
		height: 100%;
		border-radius: 50%;
		opacity: 0.2;
	}

	._dbgtxt {
		position: absolute;
		width: 100%;
		height: 100%;
		text-align: center;
		padding: 0 0.3em;
		line-height: 1.3em;
		text-shadow: 1px 1px #ffffff, -1px -1px #ffffff, -1px 1px #ffffff, 1px -1px #ffffff;
		top: 0.7em;
		left: 0;
		font-size: 0.8em;
		color: #000000;
	}
</style>

<script>
	//支持本地缓存，自动翻译
	export default {
		props: {},
		data() {
			return {
				bshow: true
			};
		},
		watch: {},
		computed: {},
		mounted() {
			this.me = this.getme();
		},
		methods: {
			async chguser(item) {
				var retjson = await this.callfunc({
					func: 'login.debug_chguser',
					data: {
						code: item.data.id
					}
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.me = this.objdeepmerge(this.me, retjson.me);
				getApp().setuserstorage(retjson);
				var page = this.com_getpage();
				page.me = this.me;
				if (page.dbgcallback)
					page.dbgcallback();
			},
			async mehide(item) {
				this.bshow = false;
				if (item.data > 0) {
					setTimeout(() => {
						this.bshow = true;
					}, item.data);
				}
			},
			async showdbglist() {
				var retjson = await this.callfunc({
					func: 'login.debug_list',
					cache: 3600,
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				var items = [];
				for (var i = 0; i < retjson.list.length; i++) {
					items.push({
						func: 'chguser',
						name: retjson.list[i].name,
						data: retjson.list[i]
					});
				}
				items.push({
					br: true
				});
				items.push({
					func: 'mehide',
					name: '消失5秒',
					style: 'color:var(--warn6)',
					data: 5000
				});
				items.push({
					func: 'mehide',
					name: '永久隐藏',
					style: 'color:var(--dag6)',
					data: 0
				});
				this.popmenu({
					rowcount: 3,
					items
				});
			},
		}
	}
</script>