indexOld.nvue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <view class="live-pusher-box" :style="{width: width + 'px',height: height + 'px'}">
  3. <Ba-CameraView ref="cameraView" :load="loadData" :style="{flex: 1,width: width + 'px',display:'none'}" ></Ba-CameraView>
  4. <cover-view class="cover-view" :style="{width: width + 'px',height: height + 'px'}">
  5. <cover-view class="uni-nav-bar" :style="{width: width + 'px'}">
  6. <cover-view :style="{height: statusBarHeight,width: width + 'px'}"></cover-view>
  7. <cover-view class="uni-nav-barbox">
  8. <cover-view class="flex-center boder-box" @click="back">
  9. <cover-image class="uni-nav-back" src="@/static/image/device/back_icon33.png" mode="aspectFill"></cover-image>
  10. <text class="uni-nav-title-t">返回</text>
  11. </cover-view>
  12. </cover-view>
  13. </cover-view>
  14. <cover-view class="title-box" :style="{width: width + 'px'}">
  15. <cover-view :style="{height: statusBarHeight,width: width + 'px'}"></cover-view>
  16. <text class="title">请拍摄舌面</text>
  17. <text class="tips">舌尖放松,舌面平展,舌尖略向下,口张大不要太用力</text>
  18. </cover-view>
  19. <cover-view class="imagebox" :style="{width:width + 'px',height: height + 'px'}">
  20. <!-- <view v-if="width<height" :style="{width:width + 'px',height: height/4+ 'px'}" style="background:#262523 ;"></view> -->
  21. <!-- <image v-if="width>height" class="tongue" :style="{width: width + 'px',height: height + 'px'}" src="@/static/image/device/lingual_surface_mask.png" mode="aspectFill"></image>
  22. <image v-if="width<height" class="tongue" :style="{width: width + 'px',height: height/1.5 + 'px'}" src="@/static/image/device/lingual_surface_mask.png" mode="aspectFill"></image> -->
  23. </cover-view>
  24. </cover-view>
  25. </cover-view>
  26. <view class="camera-footer" id="camera-footer" :style="{width: width + 'px'}">
  27. <view class="camera-options" :style="{width: width + 'px'}">
  28. <view class="camera-options-left camera-item" @click="handleAlbum">
  29. <image src="@/static/image/device/album_icon24.png" mode="scaleToFill" style="width: 34rpx;height:34rpx;margin-bottom: 5rpx;"></image>
  30. <text class="camera-item-t">相册上传</text>
  31. </view>
  32. <view class="camera-options-center camera-item" @click="handleShutter">
  33. <view class="photograph-btn"></view>
  34. </view>
  35. <view class="camera-options-ritht camera-item" @click="handleReversal">
  36. <image src="@/static/image/device/switch_camera_icon24.png" mode="scaleToFill" style="width: 34rpx;height:34rpx;margin-bottom: 5rpx;"></image>
  37. <text class="camera-item-t">切换摄像头</text>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { isAgreePrivacy } from '@/utils/common.js'
  45. import shareBox from "@/components/share-box/share-boxN.vue"
  46. import {getCount} from '@/api/healthTongue.js'
  47. import { premissionCheck } from "@/js_sdk/wa-permission/permission.js"
  48. // 这个组件仅限APP使用!!!
  49. export default {
  50. components: {
  51. shareBox
  52. },
  53. data() {
  54. // 在data初始化时就进行设备检测
  55. const systemInfo = uni.getSystemInfoSync();
  56. console.log('设备信息:', systemInfo);
  57. // // 判断是否为平板设备
  58. // const isTabletBySize = systemInfo.screenWidth > 800 && systemInfo.screenHeight > 1200;
  59. const isTabletByModel = systemInfo.brand && (
  60. //systemInfo.model.toLowerCase().includes('tablet') ||
  61. //systemInfo.model.toLowerCase().includes('pad') ||
  62. systemInfo.brand.toLowerCase().includes('shimeta')
  63. );
  64. const isTablet = isTabletByModel;
  65. const defaultCameraFacing = isTablet ? false : true; // 平板默认后置,手机默认前置
  66. console.log('设备检测结果:', {
  67. isTablet,
  68. defaultCameraFacing: defaultCameraFacing ? '前置' : '后置',
  69. screenSize: `${systemInfo.screenWidth}x${systemInfo.screenHeight}`,
  70. model: systemInfo.model
  71. });
  72. return {
  73. baseUrl:uni.getStorageSync('requestPath'),
  74. height: uni.getSystemInfoSync().screenHeight,
  75. width: uni.getSystemInfoSync().screenWidth,
  76. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  77. livePusher: null,
  78. ready: true,
  79. cameraHeight: '', //相机画面宽度
  80. coverImage: null,
  81. counts: 0,
  82. marginTop: uni.getSystemInfoSync().statusBarHeight + uni.upx2px(130),
  83. device: 'back',
  84. cameraContext: null,
  85. shutterShow: false,
  86. menuLeft: '100%',
  87. // 设备类型检测
  88. isTablet: isTablet,
  89. isShimeta: isTablet,
  90. loadData: { //配置
  91. isToast: false,
  92. isShowVibrate:false,
  93. isFacingFront: defaultCameraFacing, // 根据设备类型设置默认摄像头
  94. captureQuality:"HIGH", //摄像头清晰度 **HIGH**: 1920x1080 (高清) **MEDIUM**: 1280x720 (中等) **LOW**: 640x480 (低清)
  95. autoZoomEnabled: true, // 启用自动变焦
  96. autoZoomMode: "TONGUE", // 变焦模式:FACE(面部) 或 TONGUE(舌诊)
  97. isTablet: isTablet // 设备类型配置
  98. },
  99. currentQuality:0,
  100. currentZoomMode:"TONGUE", // 默认使用舌诊模式
  101. isShowCamera:false,
  102. statusMessage:"",
  103. windowResizeCallback:null
  104. }
  105. },
  106. created(){
  107. let that=this;
  108. uni.$on('navigateBack', function(data) {
  109. that.handleReversal();
  110. });
  111. },
  112. onLoad() {
  113. //this.setListener();
  114. console.log('onLoad - 当前配置:', {
  115. isTablet: this.isTablet,
  116. isFacingFront: this.loadData.isFacingFront,
  117. statusMessage: this.statusMessage
  118. });
  119. },
  120. mounted() {
  121. // 强制应用配置,确保平板设备使用后置摄像头
  122. this.$nextTick(() => {
  123. //this.forceApplyConfig();
  124. });
  125. },
  126. onShow() {
  127. this.windowResizeCallback = (res) => {
  128. // 重新获取屏幕尺寸
  129. this.getScreenSize(res.size);
  130. }
  131. uni.onWindowResize(this.windowResizeCallback);
  132. },
  133. onUnload() {
  134. if (this.windowResizeCallback) {
  135. uni.offWindowResize(this.windowResizeCallback);
  136. this.windowResizeCallback = null;
  137. }
  138. uni.$off('navigateBack');
  139. },
  140. methods: {
  141. getScreenSize(res) {
  142. this.width = res.windowWidth
  143. this.height = res.windowHeight
  144. if (this.$refs.cameraView) {
  145. this.switchZoomMode(this.loadData.autoZoomMode);
  146. } else {
  147. console.warn("Ba-CameraView 组件尚未初始化,暂不执行 setAutoZoom");
  148. }
  149. },
  150. switchZoomMode1(currentMode) {
  151. //启动舌诊模式自动变焦
  152. this.$refs.cameraView.setAutoZoom((result) => {
  153. if (result.ok) {
  154. console.log('自动变焦设置成功:', this.loadData.autoZoomMode);
  155. } else {
  156. console.error('自动变焦模式:', result.msg);
  157. }
  158. }, {
  159. enabled: this.loadData.autoZoomEnabled,
  160. mode: currentMode
  161. });
  162. },
  163. switchZoomMode() {
  164. // 在 FACE、TONGUE、DEFAULT 之间切换
  165. const modes = ['FACE', 'TONGUE', 'DEFAULT'];
  166. const currentIndex = modes.indexOf(this.currentZoomMode);
  167. this.currentZoomMode = modes[(currentIndex + 1) % modes.length];
  168. if (this.loadData.autoZoomEnabled) {
  169. this.$refs.cameraView.setAutoZoom((result) => {
  170. if (result.ok) {
  171. this.statusMessage = `变焦模式已切换到: ${this.currentZoomMode}`;
  172. console.log('Zoom mode switched to:', this.currentZoomMode);
  173. } else {
  174. this.statusMessage = '切换变焦模式失败: ' + result.msg;
  175. console.error('Failed to switch zoom mode:', result.msg);
  176. }
  177. }, {
  178. enabled: this.loadData.autoZoomEnabled,
  179. mode: this.currentZoomMode
  180. });
  181. } else {
  182. this.statusMessage = `变焦模式已设置为: ${this.currentZoomMode} (需开启自动变焦)`;
  183. this.showToast(this.statusMessage);
  184. }
  185. },
  186. getCount(){
  187. getCount().then(
  188. res => {
  189. if(res.code==200){
  190. this.counts=res.data;
  191. }else{
  192. uni.showToast({
  193. icon:'none',
  194. title: "请求失败",
  195. });
  196. }
  197. },
  198. rej => {}
  199. );
  200. },
  201. // 快门
  202. handleShutter() {
  203. if (this.ready) {
  204. this.ready = false;
  205. let options={scaleW:620,scaleH:800,isCrop:false};
  206. this.$refs.cameraView.takePicture((res) => {
  207. this.ready = true;
  208. const filePath=res.data.path;
  209. console.log("qxj takePicture",res);
  210. plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
  211. let url= entry.toLocalURL();
  212. uni.redirectTo({
  213. url:"/pages/device/tongue/index?leftUrl="+url
  214. })
  215. }, (error) => {
  216. console.error('Failed to resolve file system URL:', error);
  217. });
  218. },options);
  219. }
  220. },
  221. // 相册
  222. async handleAlbum() {
  223. // #ifdef APP-PLUS
  224. uni.chooseImage({
  225. count: 1, //默认9
  226. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  227. sourceType: ['album'], //从相册选择
  228. success: (res) => {
  229. uni.setStorageSync("tongueUrl",res.tempFilePaths[0])
  230. let url= res.tempFilePaths[0]
  231. uni.redirectTo({
  232. url:"/pages/device/tongue/index?leftUrl="+url
  233. })
  234. }
  235. });
  236. // #endif
  237. },
  238. // 反转摄像头
  239. handleReversal() {
  240. if(this.isShimeta){
  241. uni.showToast({
  242. title:"该设备不支持切换摄像头",
  243. icon:"none"
  244. });
  245. return;
  246. }
  247. this.switchZoomMode(this.loadData.autoZoomMode);
  248. this.$refs.cameraView.switchCamera((result) => {
  249. if (result.ok) {
  250. this.loadData.isFacingFront = !this.loadData.isFacingFront;
  251. this.statusMessage = `已切换到${this.loadData.isFacingFront ? '前置' : '后置'}摄像头`;
  252. uni.showToast({
  253. title: "切换成功",
  254. icon: 'none'
  255. });
  256. } else {
  257. this.statusMessage = '切换摄像头失败: ' + result.msg;
  258. console.error('操作失败', result.msg);
  259. }
  260. });
  261. },
  262. // 设置为后置摄像头
  263. setRearCamera() {
  264. this.$refs.cameraView.setCameraFacing((result) => {
  265. if (result.ok) {
  266. this.loadData.isFacingFront = false;
  267. this.statusMessage = '已设置为后置摄像头';
  268. uni.showToast({
  269. title: "已设置为后置摄像头",
  270. icon: 'none'
  271. });
  272. } else {
  273. this.statusMessage = '设置后置摄像头失败: ' + result.msg;
  274. uni.showToast({
  275. title: "设置失败: " + result.msg,
  276. icon: 'none'
  277. });
  278. }
  279. }, {
  280. useFrontCamera: false
  281. });
  282. },
  283. // 强制应用当前配置(确保平板设备配置生效)
  284. forceApplyConfig() {
  285. console.log('强制应用配置:', this.loadData);
  286. // 如果是平板设备,确保使用后置摄像头
  287. if (this.isTablet && this.loadData.isFacingFront) {
  288. console.log('检测到平板设备使用前置摄像头,强制切换到后置');
  289. this.loadData.isFacingFront = false;
  290. this.statusMessage = '平板设备强制使用后置摄像头';
  291. // 调用底层API确保配置生效
  292. this.setRearCamera();
  293. // 平板设备切换摄像头后,重新应用自动变焦设置
  294. if (this.loadData.autoZoomEnabled) {
  295. setTimeout(() => {
  296. this.reapplyAutoZoom();
  297. }, 1000); // 等待摄像头切换完成
  298. }
  299. }
  300. // 更新状态显示
  301. this.statusMessage = this.isTablet ?
  302. '平板设备 - 后置摄像头' :
  303. (this.loadData.isFacingFront ? '手机设备 - 前置摄像头' : '手机设备 - 后置摄像头');
  304. },
  305. // 重新应用自动变焦设置
  306. reapplyAutoZoom() {
  307. console.log('重新应用自动变焦设置:', {
  308. enabled: this.loadData.autoZoomEnabled,
  309. mode: this.currentZoomMode
  310. });
  311. this.$refs.cameraView.setAutoZoom((result) => {
  312. if (result.ok) {
  313. this.statusMessage = `平板设备 - 自动变焦已重新应用 (${this.currentZoomMode}模式)`;
  314. console.log('平板设备自动变焦重新应用成功');
  315. } else {
  316. this.statusMessage = '重新应用自动变焦失败: ' + result.msg;
  317. console.error('Failed to reapply auto zoom:', result.msg);
  318. }
  319. }, {
  320. enabled: this.loadData.autoZoomEnabled,
  321. mode: this.currentZoomMode
  322. });
  323. },
  324. // 舌诊记录
  325. handleReportlist() {
  326. uni.navigateTo({
  327. url: "/pages/user/tongue/tongueList"
  328. })
  329. },
  330. setListener() {
  331. this.$refs.cameraView.setListener((res) => {
  332. if (res.action == "error") {
  333. this.showToast(res.msg)
  334. }
  335. });
  336. },
  337. showToast(msg) {
  338. uni.showToast({
  339. title: msg,
  340. icon: 'none'
  341. });
  342. },
  343. navTo() {
  344. uni.navigateTo({
  345. url: "/pages/device/tongue/ques"
  346. })
  347. },
  348. // 返回
  349. back(){
  350. uni.navigateBack();
  351. },
  352. }
  353. }
  354. </script>
  355. <style lang="scss" scoped>
  356. @mixin u-flex($flexD, $alignI, $justifyC) {
  357. display: flex;
  358. flex-direction: $flexD;
  359. align-items: $alignI;
  360. justify-content: $justifyC;
  361. }
  362. .flex-center {
  363. @include u-flex(row, center, center);
  364. }
  365. .live-pusher-box {
  366. @include u-flex(column, center, center);
  367. }
  368. .imagebox {
  369. top:0;
  370. left: 0;
  371. right: 0; // 新增:让容器铺满屏幕宽度,确保文本居中生效
  372. overflow: hidden;
  373. display: flex;
  374. flex-direction: column;
  375. align-items: center;
  376. justify-content: center;
  377. padding-bottom: 100rpx;
  378. }
  379. .tongue {
  380. width: 100%;
  381. }
  382. .cover-view {
  383. width: 100%;
  384. position: absolute;
  385. top: 0;
  386. left: 0;
  387. @include u-flex(column, center, center);
  388. }
  389. .title-box{
  390. position: fixed;
  391. top: 20px;
  392. left: 0;
  393. right: 0; // 新增:让容器铺满屏幕宽度,确保文本居中生效
  394. z-index: 998; // 低于导航栏 z-index:999,避免遮挡导航栏
  395. width: 100%;
  396. }
  397. .title {
  398. // margin-top: calc(var(--status-bar-height) + 130rpx);
  399. font-family: SourceHanSansCN-Medium;
  400. font-weight: 500;
  401. font-size: 18rpx;
  402. color: #fff;
  403. text-align: center;
  404. }
  405. .tips {
  406. margin-top: 20rpx;
  407. // margin-bottom: 60rpx;
  408. font-family: SourceHanSansSC-Regular;
  409. font-weight: 400;
  410. font-size: 16rpx;
  411. color: #fff;
  412. text-align: center;
  413. }
  414. .boder-box{
  415. width: 66rpx;
  416. height: 32rpx;
  417. background: rgba(255,255,255,0.2);
  418. border-radius: 8rpx;
  419. border: 1px solid #FFFFFF;
  420. }
  421. .uni-nav-bar {
  422. position: fixed;
  423. top: 20px;
  424. left: 0;
  425. width: 100%;
  426. z-index: 999;
  427. overflow: hidden;
  428. font-family: PingFang SC, PingFang SC;
  429. font-weight: 500;
  430. color: #fff;
  431. // background-color: #000;
  432. .uni-nav-barbox {
  433. // width: 100%;
  434. // height: 88rpx;
  435. padding: 0 24rpx;
  436. // box-sizing: border-box;
  437. // @include u-flex(row, center,space-between);
  438. // position: relative;
  439. font-size: 24rpx;
  440. }
  441. .uni-nav-title-t {
  442. font-family: SourceHanSansSC;
  443. font-weight: 400;
  444. margin-left: 5rpx;
  445. color: #fff;
  446. /* #ifdef APP-PLUS */
  447. font-size: 14rpx;
  448. /* #endif */
  449. /* #ifndef APP-PLUS */
  450. font-size: 14rpx;
  451. /* #endif */
  452. }
  453. .uni-nav-title {
  454. // flex-shrink: 0;
  455. font-family: SourceHanSansSC;
  456. font-weight: 400;
  457. color: #fff;
  458. /* #ifdef APP-PLUS */
  459. font-size: 14rpx;
  460. /* #endif */
  461. /* #ifndef APP-PLUS */
  462. font-size: 14rpx;
  463. /* #endif */
  464. @include u-flex(row, center, flex-start);
  465. .ques {
  466. // flex-shrink: 0;
  467. width: 33rpx;
  468. height: 33rpx;
  469. margin-left: 9rpx;
  470. }
  471. }
  472. .uni-nav-back {
  473. width: 16rpx;
  474. height: 16rpx;
  475. }
  476. }
  477. // .center-box{
  478. // width: 100%;
  479. // display: flex;
  480. // align-items: center;
  481. // justify-content: space-around;
  482. // }
  483. .camera-footer {
  484. background-color: #000;
  485. overflow: hidden;
  486. position: fixed;
  487. bottom: 0;
  488. left: 0;
  489. }
  490. .usenum {
  491. text-align: center;
  492. @include u-flex(row, center, center);
  493. .usenum-t {
  494. font-family: SourceHanSansCN;
  495. font-weight: 400;
  496. font-size: 24rpx;
  497. color: #FFFFFF;
  498. padding: 14rpx;
  499. }
  500. }
  501. .camera-options {
  502. width: 100%;
  503. padding-top: 15rpx;
  504. padding-bottom: 15rpx;
  505. // box-sizing: border-box;
  506. @include u-flex(row, center, space-around);
  507. }
  508. .camera-item {
  509. display: flex;
  510. flex-direction: column;
  511. align-items: center;
  512. }
  513. .camera-item-t {
  514. font-family: SourceHanSansCN;
  515. font-weight: 400;
  516. font-size: 16rpx;
  517. color: #FFFFFF;
  518. }
  519. .camera-options-center {
  520. width: 52rpx;
  521. height: 52rpx;
  522. border-radius: 50%;
  523. border-radius: 50%;
  524. border: 3px solid #FFFFFF;
  525. display: flex;
  526. align-items: center;
  527. justify-content: center;
  528. }
  529. .photograph-btn {
  530. width: 45rpx;
  531. height: 45rpx;
  532. background: #8F6726;
  533. border-radius: 50%;
  534. }
  535. </style>