facePhoto.nvue 14 KB

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