12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <template>
- <view id="barcode" style="background-color: #18B566;width: 100%;height: 100%"></view>
- </template>
- <script>
- export default {
- data() {
- return {
- // #ifdef APP-PLUS
- barcode: [
- plus.barcode.CODE39,
- plus.barcode.CODE93,
- plus.barcode.CODE128,
- ], //码类型
- bug:'',
- // #endif
- };
- },
- created() {
-
- var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //状态栏
- var height = statusBarHeight + 44 + 144 + 'px';
- var pages = getCurrentPages();
- var page = pages[pages.length - 1];
- // #ifdef APP-PLUS
- var currentWebview = page.$getAppWebview();
- this.barcode = plus.barcode.create('barcode', this.barcode, {
- top: '0',
- left: '0',
- width: '100%',
- height: '50%', //180px
- position: 'static',
- background: '#ffffff',
- frameColor: '#00A0EA',
- scanbarColor: '#00A0EA'
- });
- this.barcode.onmarked = this.onmarked;
- currentWebview.append(this.barcode);
- const res = uni.getSystemInfoSync();
- if (res.platform == 'android') { //安卓机
- this.barcode.start();
- }
- this.barcode.setStyle({
- });
- // #endif
- },
- onUnload() {
- clearTimeout(this.t);
- },
- methods: {
- onmarked(type, result) {
- // console.log(type +':'+ result);
- this.$emit('getCode', result);
- this.t = setTimeout(() => {
- this.barcode.start();
- }, 1000)
- }
- }
- }
- </script>
- <style lang="less">
- </style>
|