companyvideo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <<template>
  2. <view class="page">
  3. <view class='content'>
  4. <view class='row'>
  5. <view class='img-video'>
  6. <view class="video-content">
  7. <KJ-Camera ref='Camera' class="KJ-Camera" :style="{width:'100%',height:cameraHeight}">
  8. </KJ-Camera>
  9. </view>
  10. </view>
  11. </view>
  12. <view class='row2'>
  13. 请将头像放于圆圈内,并阅读以下文字
  14. </view>
  15. <view class='row2 text'>
  16. 网络客服过段时间浪费多少级范德萨快逻辑范德萨拉丝机多亏了房价按时付款了金坷垃所肩负的看离开静安寺了发动机as在考虑家双方都会计分录卡死范德萨拉使肌肤抵抗力
  17. </view>
  18. <view class='btn'>
  19. <!-- <view class="verify-btn" @click="getCamera" v-show="!showVideo">打开摄像头</view> -->
  20. <view class='video-btn'>
  21. <view class="verify-btn" @click="saveVideo" v-if='!isAlreadyRecord'>开始录制</view>
  22. <view class="verify-btn" @click="saveVideo" v-if='isAlreadyRecord' data-action="navigateTo">结束录制
  23. </view>
  24. <!-- <button class="video-close" @click="closeVideo">×</button>
  25. <button class="video-save" @click="saveVideo">
  26. {{ isAlreadyRecord ? '结束录制(' + count + 's)' : '开始录制' }}</button> -->
  27. </view>
  28. </view>
  29. <!-- <video ref="videob" controls="" name="media" width="100%" height="100"></video> -->
  30. </view>
  31. <!-- <view class="btn-view">
  32. <button @click="captureImage" class="btn" type="primary">
  33. 拍照
  34. </button>
  35. <button @click="startVideoCapture" class="btn" type="primary">
  36. 开始录像
  37. </button>
  38. <button @click="stopVideoCapture" class="btn" type="primary">
  39. 停止录像
  40. </button>
  41. <button @click="switchCamera" class="btn" type="primary">
  42. 前后摄像头切换
  43. </button>
  44. <button @click="setZoomFactor" class="btn" type="primary">
  45. 设置焦距
  46. </button>
  47. <button @click="setFlash" class="btn" type="primary">
  48. 设置闪光灯模式
  49. </button>
  50. <button @click="setTorch" class="btn" type="primary">
  51. 设置手电筒
  52. </button>
  53. <button @click="ios_getSessionPresets" class="btn" type="primary">
  54. ios获取支持的分辨率
  55. </button>
  56. <button @click="ios_setSessionPreset" class="btn" type="primary">
  57. ios设置分辨率
  58. </button>
  59. <button @click="android_getSupportedPictureSizes" class="btn" type="primary">
  60. android获取照片支持分辨率列表
  61. </button>
  62. <button @click="android_getSupportedPreviewSizes" class="btn" type="primary">
  63. android获取预览支持分辨率列表
  64. </button>
  65. <button @click="android_getSupportedVideoSizes" class="btn" type="primary">
  66. android获取视频支持分辨率列表
  67. </button>
  68. <button @click="android_setCameraParams" class="btn" type="primary">
  69. android设置相机参数
  70. </button>
  71. <button @click="setRotation" class="btn" type="primary">
  72. android设置旋转角度
  73. </button>
  74. <button @click="initCamera" class="btn" type="primary">
  75. 初始化相机
  76. </button>
  77. <image :src="src" style="width: 50px;height: 50px;"></image>
  78. </view> -->
  79. </view>
  80. </template>
  81. <script>
  82. var videoFilePath;
  83. export default {
  84. data() {
  85. return {
  86. cameraWidth: "100%",
  87. cameraHeight: "auto",
  88. src: ""
  89. }
  90. },
  91. onReady() {
  92. console.log("onReady")
  93. // this.$refs.Camera.initCamera();
  94. },
  95. methods: {
  96. /**
  97. * 初始化相机 默认加载插件的时候已初始化
  98. * 在横竖屏切换的时候,需要重新初始化,要不然画面是颠倒的
  99. * */
  100. initCamera() {
  101. this.$refs.Camera.initCamera();
  102. },
  103. /**
  104. * 拍照
  105. * */
  106. captureImage() {
  107. var _this = this;
  108. var dic = {
  109. "savePath": plus.io.convertLocalFileSystemURL("_doc/KJ-Camera"), //保存图片位置,一定要是_doc绝对路径
  110. "format": "jpeg", //保存的图片格式 有效值:png、jpeg
  111. "quality": 80 //andorid才可用 保存的图片质量,取值1-100
  112. }
  113. this.$refs.Camera.captureImage(dic, (res) => {
  114. console.log("filePath: " + res)
  115. //_this.src = "file://" + res.filePath;
  116. uni.saveImageToPhotosAlbum({
  117. filePath: plus.io.convertAbsoluteFileSystem(res.filePath),
  118. success: function() {
  119. console.log('save success');
  120. },
  121. fail: function(e) {
  122. console.log(JSON.stringify(e));
  123. }
  124. });
  125. }, (res) => {
  126. _this.src = "data:image/png;base64," + res.base64;
  127. console.log("base64: " + res)
  128. });
  129. },
  130. /**
  131. * 开始录像
  132. * */
  133. startVideoCapture() {
  134. var _this = this;
  135. var dic = {
  136. "savePath": plus.io.convertLocalFileSystemURL("_doc/KJ-Camera"), //保存视频位置,一定要是_doc绝对路径
  137. "isAddAudio": true, //是否添加音频,默认是true
  138. "videoEncoder": 2, //andorid有效,DEFAULT = 0;H263 = 1;H264 = 2;MPEG_4_SP = 3;VP8 = 4;HEVC = 5;
  139. "audioEncoder": 0, //andorid有效,DEFAULT = 0;AMR_NB = 1;AMR_WB = 2;AAC = 3;HE_AAC = 4;AAC_ELD = 5;VORBIS = 6;
  140. }
  141. this.$refs.Camera.startVideoCapture(dic, (res) => {
  142. console.log("startVideoCapture: " + JSON.stringify(res))
  143. if (res.status == "start") {
  144. console.log("开始录像")
  145. } else if (res.status == "end") {
  146. console.log("结束录像")
  147. videoFilePath = res.filePath;
  148. uni.saveVideoToPhotosAlbum({
  149. filePath: plus.io.convertAbsoluteFileSystem(videoFilePath),
  150. success: function() {
  151. console.log('save success');
  152. }
  153. });
  154. }
  155. });
  156. },
  157. /**
  158. * 停止录像
  159. * */
  160. stopVideoCapture() {
  161. this.$refs.Camera.stopVideoCapture();
  162. },
  163. /**
  164. * 前后摄像头切换
  165. * */
  166. switchCamera() {
  167. this.$refs.Camera.switchCamera();
  168. this.android_setCameraParams(); //因为andorid前后摄像头,设置相机参数不一样,需要重置
  169. },
  170. /**
  171. * 设置焦距
  172. * */
  173. setZoomFactor() {
  174. this.$refs.Camera.getZoomFactor((res_zoom) => {
  175. console.log("获取当前焦距:" + res_zoom.value);
  176. this.$refs.Camera.getMaxZoomFactor((res_max) => {
  177. console.log("可设置的最大焦距:" + res_max.value);
  178. this.$refs.Camera.getMinZoomFactor((res_min) => {
  179. console.log("可设置的最小焦距:" + res_min.value);
  180. this.$refs.Camera.setZoomFactor(res_max.value);
  181. });
  182. });
  183. });
  184. },
  185. /**
  186. * 设置闪光灯模式 默认是auto
  187. * auto-自动
  188. * on-开
  189. * off-关
  190. * */
  191. setFlash() {
  192. this.$refs.Camera.setFlash("off");
  193. },
  194. /**
  195. * 设置手电筒 默认是auto
  196. * auto-自动
  197. * on-开
  198. * off-关
  199. * */
  200. setTorch() {
  201. this.$refs.Camera.setTorch("on");
  202. },
  203. /**
  204. * ios获取支持的分辨率
  205. * */
  206. ios_getSessionPresets() {
  207. this.$refs.Camera.ios_getSessionPresets((res) => {
  208. console.log("ios_getSessionPresets:" + JSON.stringify(res));
  209. });
  210. },
  211. /**
  212. * ios设置分辨率 默认是high
  213. * photo-适用于高分辨率照片质量输出
  214. * high-适用于高质量视频和音频输出
  215. * medium-适用于中等质量输出
  216. * low-适用于低质量输出
  217. * 其它。。。
  218. * */
  219. ios_setSessionPreset() {
  220. this.$refs.Camera.ios_setSessionPreset("low"); //从ios_getSessionPresets方法获取
  221. },
  222. /**
  223. * android获取照片支持分辨率列表
  224. * 只用于设置照片分辨率 或 视频分辨率
  225. * */
  226. android_getSupportedPictureSizes() {
  227. this.$refs.Camera.android_getSupportedPictureSizes((res) => {
  228. console.log("android_getSupportedPictureSizes:" + JSON.stringify(res));
  229. });
  230. },
  231. /**
  232. * android获取预览支持分辨率列表
  233. * 只用于设置预览分辨率
  234. * */
  235. android_getSupportedPreviewSizes() {
  236. this.$refs.Camera.android_getSupportedPreviewSizes((res) => {
  237. console.log("android_getSupportedPreviewSizes:" + JSON.stringify(res));
  238. });
  239. },
  240. /**
  241. * android获取视频支持分辨率列表
  242. * 只用于视频分辨率
  243. * */
  244. android_getSupportedVideoSizes() {
  245. this.$refs.Camera.android_getSupportedVideoSizes((res) => {
  246. console.log("android_getSupportedVideoSizes:" + JSON.stringify(res));
  247. });
  248. },
  249. /**
  250. * android设置旋转角度
  251. * 值参考:0,90,180,270 为null,则为自动设置
  252. * */
  253. setRotation() {
  254. this.$refs.Camera.setRotation(null);
  255. },
  256. /**
  257. * android设置相机参数
  258. * 照片和预览分辨率等于0,默认使用从支持分辨率列表中选取合适的分辨率
  259. * 其它等于0的话,不设置这个参数
  260. * */
  261. android_setCameraParams() {
  262. const res = uni.getSystemInfoSync();
  263. var screenBiLi = res.screenWidth / res.screenHeight
  264. screenBiLi = Math.floor(screenBiLi * 10) / 10;
  265. console.log("screenBiLi:" + screenBiLi)
  266. //设置最大分辨率
  267. this.$refs.Camera.android_getSupportedPictureSizes((PictureSizes) => {
  268. this.$refs.Camera.android_getSupportedPreviewSizes((PreviewSizes) => {
  269. this.$refs.Camera.android_getSupportedVideoSizes((VideoSizes) => {
  270. var maxPictureSizesIndex = 0;
  271. var maxPictureSizeWidthHeight = 0;
  272. for (var i = 0; i < PictureSizes.length; i++) {
  273. var item = PictureSizes[i];
  274. var PictureSizeBiLi = item.height / item.width;
  275. PictureSizeBiLi = Math.floor(PictureSizeBiLi * 10) / 10;
  276. console.log("PictureSizeBiLi:" + PictureSizeBiLi)
  277. if (PictureSizeBiLi == screenBiLi) {
  278. if (maxPictureSizeWidthHeight < item.width * item.height) {
  279. maxPictureSizeWidthHeight = item.width * item.height;
  280. maxPictureSizesIndex = i;
  281. }
  282. }
  283. }
  284. var maxPreviewSizesIndex = 0;
  285. var maxPreviewSizeWidthHeight = 0;
  286. for (var i = 0; i < PreviewSizes.length; i++) {
  287. var item = PreviewSizes[i];
  288. var PreviewBiLi = item.height / item.width;
  289. PreviewBiLi = Math.floor(PreviewBiLi * 10) / 10;
  290. console.log("PreviewBiLi:" + PreviewBiLi)
  291. if (PreviewBiLi == screenBiLi) {
  292. if (maxPreviewSizeWidthHeight < item.width * item.height) {
  293. maxPreviewSizeWidthHeight = item.width * item.height;
  294. maxPreviewSizesIndex = i;
  295. }
  296. }
  297. }
  298. var maxVideoSizesIndex = 0;
  299. var maxVideoSizesWidthHeight = 0;
  300. for (var i = 0; i < VideoSizes.length; i++) {
  301. var item = VideoSizes[i];
  302. // var PreviewBiLi = item.height / item.width;
  303. // PreviewBiLi = Math.floor(PreviewBiLi * 10) / 10;
  304. console.log("PreviewBiLi:" + PreviewBiLi)
  305. //if (PreviewBiLi == screenBiLi) {
  306. if (maxVideoSizesWidthHeight < item.width * item.height) {
  307. maxVideoSizesWidthHeight = item.width * item.height;
  308. maxVideoSizesIndex = i;
  309. }
  310. //}
  311. }
  312. var dic = {
  313. picSizeWidth: PictureSizes[maxPictureSizesIndex]
  314. .width, //照片分辨率宽 从android_getSupportedPictureSizes方法获取
  315. picSizeHeight: PictureSizes[maxPictureSizesIndex]
  316. .height, //照片分辨率高 从android_getSupportedPictureSizes方法获取
  317. jpegQuality: 100, //照片质量 取值1-100
  318. preSizeWidth: PreviewSizes[maxPreviewSizesIndex]
  319. .width, //预览分辨率宽 从android_getSupportedPreviewSizes方法获取
  320. preSizeHeight: PreviewSizes[maxPreviewSizesIndex]
  321. .height, //预览分辨率高 从android_getSupportedPreviewSizes方法获取
  322. videoSizeWidth: VideoSizes[maxVideoSizesIndex]
  323. .width, //视频分辨率宽 从android_getSupportedVideoSizes方法获取
  324. videoSizeHeight: VideoSizes[maxVideoSizesIndex]
  325. .height, //视频分辨率高 从android_getSupportedVideoSizes方法获取
  326. videoEncodingBitRate: 5 * VideoSizes[maxVideoSizesIndex]
  327. .width * VideoSizes[maxVideoSizesIndex]
  328. .height, //视频编码比特率,如果设置了视频分辨率,这个一定要设置,否则视频不清晰
  329. }
  330. this.$refs.Camera.android_setCameraParams(dic);
  331. console.log(JSON.stringify(dic));
  332. });
  333. });
  334. });
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="scss">
  340. .KJ-Camera {
  341. width: 100%;
  342. position: fixed;
  343. top: 0px;
  344. bottom: 0px;
  345. left: 0;
  346. right: 0;
  347. }
  348. .btn {
  349. height: 35px;
  350. width: 260px;
  351. }
  352. .btn-view {
  353. position: fixed;
  354. bottom: 0;
  355. left: 0;
  356. right: 0;
  357. }
  358. .content {
  359. background: #F5F6FA;
  360. height: 100vh;
  361. position: relative;
  362. }
  363. .row {
  364. display: flex;
  365. justify-content: center;
  366. padding-top: 50px;
  367. }
  368. .img-video {
  369. position: relative;
  370. border-radius: 280px;
  371. width: 250px;
  372. height: 250px;
  373. overflow: hidden;
  374. }
  375. .row2 {
  376. display: flex;
  377. font-size: 20px;
  378. justify-content: center;
  379. margin-top: 20px;
  380. }
  381. .verify-btn {
  382. background: #2772FB;
  383. font-size: 20px;
  384. padding: 10px 0;
  385. width: 70%;
  386. display: flex;
  387. justify-content: center;
  388. align-items: center;
  389. border-radius: 50px;
  390. color: white;
  391. }
  392. .btn {
  393. position: absolute;
  394. bottom: 0;
  395. background: white;
  396. width: 100%;
  397. display: flex;
  398. justify-content: center;
  399. padding: 40px 0;
  400. }
  401. .img {
  402. position: absolute;
  403. top: 0;
  404. bottom: 0;
  405. width: 100%;
  406. width: 564px;
  407. height: 564px;
  408. right: 0;
  409. left: 0;
  410. margin: auto;
  411. }
  412. .video-content {
  413. position: absolute;
  414. top: 0;
  415. bottom: 0;
  416. width: 100%;
  417. right: 0;
  418. left: 0;
  419. // margin: auto;
  420. }
  421. .video {
  422. width: calc(100%);
  423. background: #F5F6FA;
  424. }
  425. .video-btn {
  426. width: 100%;
  427. display: flex;
  428. justify-content: center;
  429. }
  430. .progressBar {
  431. width: 50%;
  432. height: 25px;
  433. display: block;
  434. top: 0;
  435. left: 0;
  436. bottom: 0;
  437. right: 0;
  438. // margin: auto;
  439. padding: 10px 10px 10px 10px;
  440. position: absolute;
  441. z-index: 2001;
  442. background: rgb(102, 102, 102);
  443. color: white;
  444. border-radius: 5px;
  445. }
  446. .text{
  447. padding: 20px;
  448. }
  449. </style>