Scan (扫码)
支持自定义插槽自定义扫码布局,使用插槽记得设置:mask='false'
支持平台
安卓 | ios | 鸿蒙 | web | 微信小程序 |
---|---|---|---|---|
√ | √ | √ | √ | √ |
示例代码
html
<template>
<t-page main-class="p-30">
<t-card main-class="mb-30" title="tui-scan扫码" sub-title="支持自定义插槽自定义扫码布局,使用插槽记得设置:mask='false'">
</t-card>
<t-scan v-if="show" ref="scancodeEle" :isPreviewing="isPreviewing" main-class="h-600 mb-30 tdr"
@scanned="scanned" :mode="mode" :mask="mask" type='p'>
<!-- <t-col main-class="da-twh-100%-ba-fc">
<t-text>插槽测试-使用插槽记得设置:mask='false'</t-text>
</t-col> -->
</t-scan>
<t-button main-class="mb-30" @click="switchs">{{mode=='qr'?'扫条形码':'扫二维码'}}</t-button>
<t-button main-class="mb-30" @click="closeMask">{{mask?'关闭':'打开'}}遮罩层</t-button>
<t-button main-class="mb-30" @click="open">开启扫描</t-button>
<t-button main-class="mb-30" @click="isPreviewing=!isPreviewing">{{isPreviewing?'关闭相机预览':'打开相机预览'}}</t-button>
<t-button main-class="mb-30" @click="photo">图片识别</t-button>
</t-page>
</template>
<script setup>
import { ScanResult } from '@/uni_modules/tui-scan'
const scancodeEle = ref<TScanComponentPublicInstance | null>(null)
const isPreviewing = ref(true)
const show = ref(true)
const mode = ref('bar')
const mask = ref(true)
function closeMask() {
mask.value = !mask.value
show.value = false
nextTick(() => {
show.value = true
})
}
function switchs() {
show.value = false
nextTick(() => {
if (mode.value == 'bar') {
mode.value = 'qr'
} else {
mode.value = 'bar'
}
show.value = true
})
}
function photo() {
let el = scancodeEle.value as TScanComponentPublicInstance
el.scanImage()
}
function open() {
let el = scancodeEle.value as TScanComponentPublicInstance
el.rescan()
}
function scanned(e : ScanResult) : void {
uni.showModal({
title: e.data[0].value,
success: (_) => {
}
})
}
</script>
属性
名称 | 类型 | 默认值 | 说明 | 可选值 |
---|---|---|---|---|
size | String | mini | 组件尺寸 | large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你) |
type | String | "" | 组件类型 | info(信息), primary(正常), error(错误), warning(警告), success(成功) |
disabled | Boolean | false | 组件是否禁用 | false, true |
stop | Boolean | false | 是否阻止事件冒泡(Tui统一写法处理事件冒泡) | false, true |
hover | Boolean | true | 是否有点击效果 | false, true |
path | String | "" | 点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。 | - |
mainClass | String | "" | 组件根节点的样式 | - |
nativeClass | String | "" | 组件根节点原生样式 | - |
effect | String | "normal" | 组件显示主题 | normal(正常), dark(深色), light(浅色), plain(镂空) |
mode | String | qr | 扫描模式 | qr : 扫描二维码bar : 扫条码 |
lineHeight | Number | 2 | 扫描线的高度 | |
type | String | p | 组件类型 | |
rectColor | String | `` | 矩形框颜色 | |
mask | Boolean | true | 是否显示遮罩层 | |
lineColor | String | `` | 线条颜色 | |
welcome | String | 欢迎使用Tui | 欢迎文本 | |
isPreviewing | Boolean | true | 是否开启预览 |
插槽
名称 | 返回值 | 说明 |
---|---|---|
default | - |