<template>
	<view class="page">
		<web-view src="/hybrid/html/scanner.html" @message="handleMessage"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		methods: {
			handleMessage(e) {
				const data = e.detail && e.detail.data && e.detail.data[0]
				if (!data) return
				const action = data.action || ''
				if (action === 'scanned' && data.code) {
					uni.$emit('scan-isbn-result', data.code)
					uni.navigateBack()
				} else if (action === 'close') {
					uni.navigateBack()
				}
			}
		}
	}
</script>

<style>
	.page {
		flex: 1;
		background-color: #000;
	}
</style>
