index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view class="scan-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
  5. <view class="header-content">
  6. <view class="back-btn" @click="handleBack">
  7. <text class="back-icon">‹</text>
  8. </view>
  9. <text class="header-title">小程序扫描</text>
  10. <view class="placeholder"></view>
  11. </view>
  12. </view>
  13. <!-- 扫描区域 -->
  14. <view class="scan-area">
  15. <camera
  16. device-position="back"
  17. flash="off"
  18. class="camera"
  19. @error="handleCameraError"
  20. >
  21. <!-- 扫描框 -->
  22. <view class="scan-frame">
  23. <view class="corner corner-tl"></view>
  24. <view class="corner corner-tr"></view>
  25. <view class="corner corner-bl"></view>
  26. <view class="corner corner-br"></view>
  27. </view>
  28. </camera>
  29. <!-- 底部操作按钮 -->
  30. <view class="action-buttons">
  31. <view class="action-btn" @click="handleSelectImage">
  32. <image class="btn-icon" src="/static/pages/scan/image.png" mode="aspectFit" />
  33. <text class="btn-text">导入图片</text>
  34. </view>
  35. <view class="capture-btn" @click="handleCapture">
  36. <view class="capture-inner"></view>
  37. </view>
  38. <view class="action-btn" @click="handleSelectFile">
  39. <image class="btn-icon" src="/static/pages/scan/file.png" mode="aspectFit" />
  40. <text class="btn-text">导入文档</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup>
  47. import { ref, onMounted } from 'vue'
  48. import { useI18n } from 'vue-i18n'
  49. const { t } = useI18n()
  50. // 状态栏高度
  51. const statusBarHeight = ref(0)
  52. onMounted(() => {
  53. // 获取系统信息 - 使用新API
  54. const windowInfo = uni.getWindowInfo()
  55. statusBarHeight.value = windowInfo.statusBarHeight || 0
  56. })
  57. // 返回上一页
  58. const handleBack = () => {
  59. // 返回到home页面
  60. uni.reLaunch({
  61. url: '/pages/home/index'
  62. })
  63. }
  64. // 相机错误处理
  65. const handleCameraError = (e) => {
  66. console.error('相机错误:', e)
  67. uni.showToast({
  68. title: '相机启动失败',
  69. icon: 'none'
  70. })
  71. }
  72. // 拍照
  73. const handleCapture = () => {
  74. const ctx = uni.createCameraContext()
  75. ctx.takePhoto({
  76. quality: 'high',
  77. success: (res) => {
  78. console.log('拍照成功:', res.tempImagePath)
  79. uni.showToast({
  80. title: '拍照成功',
  81. icon: 'success'
  82. })
  83. // TODO: 处理拍照后的图片
  84. },
  85. fail: (err) => {
  86. console.error('拍照失败:', err)
  87. uni.showToast({
  88. title: '拍照失败',
  89. icon: 'none'
  90. })
  91. }
  92. })
  93. }
  94. // 导入图片
  95. const handleSelectImage = () => {
  96. uni.chooseImage({
  97. count: 1,
  98. sizeType: ['original', 'compressed'],
  99. sourceType: ['album'],
  100. success: (res) => {
  101. console.log('选择图片成功:', res.tempFilePaths)
  102. uni.showToast({
  103. title: '图片导入成功',
  104. icon: 'success'
  105. })
  106. // TODO: 处理选择的图片
  107. },
  108. fail: (err) => {
  109. console.error('选择图片失败:', err)
  110. }
  111. })
  112. }
  113. // 导入文档
  114. const handleSelectFile = () => {
  115. uni.chooseMessageFile({
  116. count: 1,
  117. type: 'file',
  118. success: (res) => {
  119. console.log('选择文件成功:', res.tempFiles)
  120. uni.showToast({
  121. title: '文档导入成功',
  122. icon: 'success'
  123. })
  124. // TODO: 处理选择的文件
  125. },
  126. fail: (err) => {
  127. console.error('选择文件失败:', err)
  128. }
  129. })
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .scan-page {
  134. width: 100%;
  135. height: 100vh;
  136. display: flex;
  137. flex-direction: column;
  138. background-color: #000000;
  139. // 顶部导航栏
  140. .header-bg {
  141. background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
  142. position: relative;
  143. z-index: 100;
  144. .header-content {
  145. height: 88rpx;
  146. display: flex;
  147. align-items: center;
  148. justify-content: space-between;
  149. padding: 0 24rpx;
  150. .back-btn {
  151. width: 60rpx;
  152. height: 60rpx;
  153. display: flex;
  154. align-items: center;
  155. justify-content: flex-start;
  156. .back-icon {
  157. font-size: 56rpx;
  158. color: #ffffff;
  159. font-weight: 300;
  160. }
  161. }
  162. .header-title {
  163. flex: 1;
  164. text-align: center;
  165. font-size: 32rpx;
  166. font-weight: 600;
  167. color: #ffffff;
  168. }
  169. .placeholder {
  170. width: 60rpx;
  171. }
  172. }
  173. }
  174. // 扫描区域
  175. .scan-area {
  176. flex: 1;
  177. position: relative;
  178. display: flex;
  179. flex-direction: column;
  180. .camera {
  181. flex: 1;
  182. width: 100%;
  183. position: relative;
  184. // 扫描框
  185. .scan-frame {
  186. position: absolute;
  187. top: 50%;
  188. left: 50%;
  189. transform: translate(-50%, -50%);
  190. width: 500rpx;
  191. height: 500rpx;
  192. .corner {
  193. position: absolute;
  194. width: 60rpx;
  195. height: 60rpx;
  196. border-color: #1ec9c9;
  197. border-style: solid;
  198. &.corner-tl {
  199. top: 0;
  200. left: 0;
  201. border-width: 6rpx 0 0 6rpx;
  202. border-radius: 12rpx 0 0 0;
  203. }
  204. &.corner-tr {
  205. top: 0;
  206. right: 0;
  207. border-width: 6rpx 6rpx 0 0;
  208. border-radius: 0 12rpx 0 0;
  209. }
  210. &.corner-bl {
  211. bottom: 0;
  212. left: 0;
  213. border-width: 0 0 6rpx 6rpx;
  214. border-radius: 0 0 0 12rpx;
  215. }
  216. &.corner-br {
  217. bottom: 0;
  218. right: 0;
  219. border-width: 0 6rpx 6rpx 0;
  220. border-radius: 0 0 12rpx 0;
  221. }
  222. }
  223. }
  224. }
  225. // 底部操作按钮
  226. .action-buttons {
  227. position: absolute;
  228. bottom: 0;
  229. left: 0;
  230. right: 0;
  231. background: #ffffff;
  232. padding: 32rpx 40rpx;
  233. padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
  234. display: flex;
  235. align-items: center;
  236. justify-content: space-between;
  237. .action-btn {
  238. display: flex;
  239. flex-direction: column;
  240. align-items: center;
  241. gap: 12rpx;
  242. .btn-icon {
  243. width: 48rpx;
  244. height: 48rpx;
  245. }
  246. .btn-text {
  247. font-size: 24rpx;
  248. color: #666666;
  249. }
  250. }
  251. .capture-btn {
  252. width: 120rpx;
  253. height: 120rpx;
  254. border-radius: 50%;
  255. background: #1ec9c9;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. box-shadow: 0 4rpx 16rpx rgba(30, 201, 201, 0.4);
  260. &:active {
  261. transform: scale(0.95);
  262. }
  263. .capture-inner {
  264. width: 100rpx;
  265. height: 100rpx;
  266. border-radius: 50%;
  267. background: #ffffff;
  268. }
  269. }
  270. }
  271. }
  272. }
  273. </style>