车间能级提升-智能设备管理系统
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
  <wd-tabbar
    fixed
    v-model="tabbarStore.curIdx"
    bordered
    safeAreaInsetBottom
    placeholder
    @change="selectTabBar"
    active-color="#4D80F0"
    inactive-color="#7d7e80"
  >
    <block v-for="(item, idx) in tabbarList" :key="item.path">
      <wd-tabbar-item
        v-if="idx !== 2 && item.iconType === 'wot'"
        :title="item.text"
        :icon="item.icon"
      ></wd-tabbar-item>
      <!--TODO 扫码图标特殊处理-->
      <wd-tabbar-item
        v-if="idx === 2 && item.iconType === 'wot'"
        :title="item.text"
        :icon="item.icon"
      >
        <template #icon>
          <view class="scan-box">
            <wd-icon round name="scan" color="white" size="42rpx"></wd-icon>
          </view>
        </template>
      </wd-tabbar-item>
      <wd-tabbar-item
        v-else-if="item.iconType === 'unocss' || item.iconType === 'iconfont'"
        :title="item.text"
      >
        <template #icon>
          <view
            h-40rpx
            w-40rpx
            :class="[item.icon, idx === tabbarStore.curIdx ? 'is-active' : 'is-inactive']"
          ></view>
        </template>
      </wd-tabbar-item>
      <wd-tabbar-item v-else-if="item.iconType === 'local'" :title="item.text">
        <template #icon>
          <image :src="item.icon" h-40rpx w-40rpx />
        </template>
      </wd-tabbar-item>
    </block>
  </wd-tabbar>
</template>
 
<script setup lang="ts">
// unocss icon 默认不生效,需要在这里写一遍才能生效!注释掉也是生效的,但是必须要有!
// i-carbon-code
import { tabBar } from '@/pages.json'
import { tabbarStore } from './tabbar'
import qrcode from "@/utils/qrcode";
 
/** tabbarList 里面的 path 从 pages.config.ts 得到 */
const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
 
function selectTabBar({ value: index }: { value: number }) {
  const url = tabbarList[index].path
  // scan特殊处理
  if (index === 2) {
    tabbarStore.setCurIdx(tabbarStore.lastIdx)
 
    // 模拟成功
    // uni.navigateTo({
    //   url: `/pages/scan/index?result=GPA2024NL025`,
    // })
    // return false
    // 模拟成功
    const systemInfo = uni.getSystemInfoSync()
    if (systemInfo.uniPlatform === 'app') {
      // 只允许通过相机扫码
      uni.scanCode({
        onlyFromCamera: true,
        success: function(res) {
          console.log('条码类型:' + res.scanType)
          console.log('条码内容:' + res.result)
          if (res?.scanType !== 'QR_CODE') {
            uni.showToast({
              title: '请使用二维码进行扫码',
              icon: 'none',
            })
            return false
          }
 
          // 使用split方法截取资产编号
          // const assetCode = res.result.split('资产编号:')[1].split(' ')[0]
          uni.navigateTo({
            url: `/pages/scan/index?result=${res.result}`,
          })
        },
        fail: function (res) {},
      })
    } else {
      uni.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['camera'],
        success: function(response) {
          qrcode.decode(response.tempFilePaths[0])
          qrcode.callback = (res) => {
            console.log('res', res)
            if (res === 'error decoding QR Code') {
              uni.showToast({
                title: '二维码解析失败',
                duration: 2000,
                icon: 'none',
              })
            } else {
              uni.navigateTo({
                url: `/pages/scan/index?result=${res}`,
              })
            }
          }
        },
      })
    }
  } else {
    tabbarStore.setCurIdx(index)
    tabbarStore.setLastIdx(index)
    uni.switchTab({ url })
  }
}
 
onLoad(() => {
  // 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
  // #ifdef APP-PLUS | H5
  uni.hideTabBar({
    fail(err) {
      console.log('hideTabBar fail: ', err)
    },
    success(res) {
      console.log('hideTabBar success: ', res)
    },
  })
  // #endif
})
</script>
 
<style lang="scss" scoped>
.main-color {
  color: $uni-color-primary;
}
.scan-box {
  width: 100rpx;
  height: 100rpx;
  background-color: $uni-color-primary;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  margin-bottom: 30rpx;
}
</style>