Просмотр исходного кода

feat(custom-nav): 增加扫码功能并更新图标

- 新增 leftType 'scan' 类型,支持扫一扫功能
- 添加 scan 和 scanError 事件发射
- 替换原有文字返回按钮为 SVG 图标
- 引入多个 RemixIcon SVG 图标文件
- 更新 tab-bar 组件图标为 SVG 格式
- 修复页面路径跳转问题
- 调整图标样式与布局
mcbaiyun 1 месяц назад
Родитель
Сommit
c312d07ea9

+ 49 - 7
src/components/custom-nav.vue

@@ -5,10 +5,16 @@
       <view class="nav-left" @click="leftTypeComputed !== 'none' && handleLeft()">
         <template v-if="leftTypeComputed === 'back'">
           <!-- <uni-icons type="back" size="20" color="#333"></uni-icons> -->
-           <text class="home-text">返回</text>
+          <!-- <text class="home-text">返回</text> -->
+          <image src="/static/icons/remixicon/arrow-go-back-line.svg" class="icon" mode="widthFix" />
         </template>
         <template v-else-if="leftTypeComputed === 'home'">
-          <text class="home-text">返回首页</text>
+          <image src="/static/icons/remixicon/home-3-line.svg" class="icon" mode="widthFix" />
+          <!-- <text class="home-text">返回首页</text> -->
+        </template>
+        <template v-else-if="leftTypeComputed === 'scan'">
+          <image src="/static/icons/remixicon/qr-scan-2-line.svg" class="icon" mode="widthFix" />
+          <!-- <text class="home-text">扫一扫</text> -->
         </template>
         <template v-else>
           <!-- 占位,保持左右对称 -->
@@ -25,8 +31,8 @@ import { computed } from 'vue'
 
 interface Props {
   title: string
-  // leftType: 'back' | 'home' | 'none',默认 'back'
-  leftType?: 'back' | 'home' | 'none'
+  // leftType: 'back' | 'home' | 'none' | 'scan',默认 'back'
+  leftType?: 'back' | 'home' | 'none' | 'scan'
 }
 
 const props = withDefaults(defineProps<Props>(), {
@@ -35,6 +41,11 @@ const props = withDefaults(defineProps<Props>(), {
 
 const leftTypeComputed = computed(() => props.leftType || 'back')
 
+const emit = defineEmits<{
+  (e: 'scan', payload: any): void
+  (e: 'scanError', err: any): void
+}>()
+
 const handleLeft = () => {
   const t = leftTypeComputed.value
   if (t === 'home') {
@@ -51,6 +62,28 @@ const handleLeft = () => {
     }
     return
   }
+
+  if (t === 'scan') {
+    // 发起扫一扫,并将结果通过事件抛出给使用者(页面)处理
+    try {
+      uni.scanCode({
+        onlyFromCamera: false,
+        success: (res: any) => {
+          console.log('[custom-nav] scan success', res)
+          emit('scan', res)
+        },
+        fail: (err: any) => {
+          console.error('[custom-nav] scan failed', err)
+          emit('scanError', err)
+        }
+      })
+    } catch (err) {
+      console.error('[custom-nav] scan exception', err)
+      emit('scanError', err)
+    }
+    return
+  }
+
   if (t === 'back') {
     uni.navigateBack()
   }
@@ -58,6 +91,12 @@ const handleLeft = () => {
 </script>
 
 <style scoped>
+.icon {
+  width: 40rpx;
+  height: 40rpx;
+  margin-left: -30px;
+  display: inline-block;
+}
 .custom-nav {
   position: fixed;
   top: 0;
@@ -78,7 +117,8 @@ const handleLeft = () => {
   margin-top: 2px;
   display: flex;
   align-items: center;
-  height: 44px; /* increased to give more vertical space */
+  height: 44px;
+  /* increased to give more vertical space */
   padding: 3px 15px;
 }
 
@@ -97,10 +137,12 @@ const handleLeft = () => {
 .nav-title {
   flex: 1;
   text-align: center;
-  font-size: 18px; /* slightly larger */
+  font-size: 18px;
+  /* slightly larger */
   font-weight: 600;
   color: #333;
-  padding-block: 6px; /* nudge title down a bit for more top margin */
+  padding-block: 6px;
+  /* nudge title down a bit for more top margin */
 }
 
 .nav-right {

+ 11 - 3
src/components/tab-bar.vue

@@ -1,15 +1,18 @@
 <template>
   <view class="tab-bar">
     <view class="tab-item" @click="onTabClick(0)">
-      <uni-icons type="home" size="20" color="#666"></uni-icons>
+      <!-- <uni-icons type="home" size="20" color="#666"></uni-icons> -->
+       <image src="/static/icons/remixicon/home-3-line.svg" class="icon" mode="widthFix" />
       <text class="tab-text">慢病首页</text>
     </view>
     <view class="tab-item" @click="onTabClick(1)">
-      <uni-icons type="bars" size="20" color="#666"></uni-icons>
+      <image src="/static/icons/remixicon/line-chart-line.svg" class="icon" mode="widthFix" />
+      <!-- <uni-icons type="bars" size="20" color="#666"></uni-icons> -->
       <text class="tab-text">健康数据</text>
     </view>
     <view class="tab-item" @click="onTabClick(2)">
-      <uni-icons type="person" size="20" color="#666"></uni-icons>
+      <image src="/static/icons/remixicon/account-circle-line.svg" class="icon" mode="widthFix" />
+      <!-- <uni-icons type="person" size="20" color="#666"></uni-icons> -->
       <text class="tab-text">个人中心</text>
     </view>
   </view>
@@ -53,6 +56,11 @@ const onTabClick = (index: number) => {
 </script>
 
 <style>
+.icon {
+  width: 50rpx;
+  height: 50rpx;
+  display: inline-block;
+}
 .tab-bar {
   position: fixed;
   bottom: 0;

+ 2 - 2
src/pages/patient/health/index.vue

@@ -60,11 +60,11 @@ import TabBar from '@/components/tab-bar.vue'
 const title = ref('健康数据')
 
 const openDetail = (type: string) => {
-  uni.navigateTo({ url: `patient/patient/health/details/${type}` })
+  uni.navigateTo({ url: `details/${type}` })
 }
 
 const openReminder = () => {
-  uni.navigateTo({ url: 'patient/patient/health/reminder' })
+  uni.navigateTo({ url: 'reminder' })
 }
 </script>
 

+ 12 - 1
src/pages/public/index/index.vue

@@ -1,5 +1,5 @@
 <template>
-  <CustomNav title="慢病APP" leftType="none" />
+  <CustomNav title="慢病APP" leftType="scan" @scan="handleScan" />
   <view class="content">
     <!-- 轮播图 -->
     <swiper class="banner-swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :circular="true">
@@ -37,6 +37,17 @@ const cards = [
   { title: '健康咨询', desc: '在线咨询医生' },
   { title: '用药提醒', desc: '设置用药提醒' }
 ]
+
+function handleScan(res: any) {
+  console.log('[index] scan result', res)
+  const resultText = res?.result || ''
+  if (resultText) {
+    // 简单演示:弹出内容,实际可根据业务解析并跳转
+    uni.showToast({ title: String(resultText), icon: 'none', duration: 2000 })
+  } else {
+    uni.showToast({ title: '未识别到有效内容', icon: 'none' })
+  }
+}
 </script>
 
 <style>

+ 1 - 0
src/static/icons/remixicon/account-circle-line.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="32" height="32" fill="rgba(116,116,116,1)"><path d="M12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2ZM12.1597 16C10.1243 16 8.29182 16.8687 7.01276 18.2556C8.38039 19.3474 10.114 20 12 20C13.9695 20 15.7727 19.2883 17.1666 18.1081C15.8956 16.8074 14.1219 16 12.1597 16ZM12 4C7.58172 4 4 7.58172 4 12C4 13.8106 4.6015 15.4807 5.61557 16.8214C7.25639 15.0841 9.58144 14 12.1597 14C14.6441 14 16.8933 15.0066 18.5218 16.6342C19.4526 15.3267 20 13.7273 20 12C20 7.58172 16.4183 4 12 4ZM12 5C14.2091 5 16 6.79086 16 9C16 11.2091 14.2091 13 12 13C9.79086 13 8 11.2091 8 9C8 6.79086 9.79086 5 12 5ZM12 7C10.8954 7 10 7.89543 10 9C10 10.1046 10.8954 11 12 11C13.1046 11 14 10.1046 14 9C14 7.89543 13.1046 7 12 7Z"></path></svg>

+ 1 - 0
src/static/icons/remixicon/arrow-go-back-line.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="32" height="32" fill="rgba(116,116,116,1)"><path d="M5.82843 6.99955L8.36396 9.53509L6.94975 10.9493L2 5.99955L6.94975 1.0498L8.36396 2.46402L5.82843 4.99955H13C17.4183 4.99955 21 8.58127 21 12.9996C21 17.4178 17.4183 20.9996 13 20.9996H4V18.9996H13C16.3137 18.9996 19 16.3133 19 12.9996C19 9.68584 16.3137 6.99955 13 6.99955H5.82843Z"></path></svg>

+ 1 - 0
src/static/icons/remixicon/home-3-line.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="32" height="32" fill="rgba(116,116,116,1)"><path d="M19 21H5C4.44772 21 4 20.5523 4 20V11L1 11L11.3273 1.6115C11.7087 1.26475 12.2913 1.26475 12.6727 1.6115L23 11L20 11V20C20 20.5523 19.5523 21 19 21ZM6 19H18V9.15745L12 3.7029L6 9.15745V19ZM8 15H16V17H8V15Z"></path></svg>

+ 1 - 0
src/static/icons/remixicon/line-chart-line.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="32" height="32" fill="rgba(116,116,116,1)"><path d="M5 3V19H21V21H3V3H5ZM20.2929 6.29289L21.7071 7.70711L16 13.4142L13 10.415L8.70711 14.7071L7.29289 13.2929L13 7.58579L16 10.585L20.2929 6.29289Z"></path></svg>

+ 1 - 0
src/static/icons/remixicon/qr-scan-2-line.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="32" height="32" fill="rgba(116,116,116,1)"><path d="M15 3H21V8H19V5H15V3ZM9 3V5H5V8H3V3H9ZM15 21V19H19V16H21V21H15ZM9 21H3V16H5V19H9V21ZM3 11H21V13H3V11Z"></path></svg>