UNPKG

minix-template

Version:

minix template

839 lines (837 loc) 20.2 kB
/* * @Description: * @Autor: tangsj * @Date: 2022-04-28 16:29:05 * @LastEditTime: 2022-05-23 16:35:58 */ import router from '@system.router' import prompt from '@system.prompt' export default { data: { mediaList:[ { name:'scanCode', // url:'pages/base/canlUse/index', describe:'扫码' }, { name:'openShare', // url:'pages/base/log/index', describe:'分享(可分享文本、图片、链接)' }, { name:'playAudio', // url:'pages/base/canlUse/index', describe:'播放录音' }, { name:'startRecord', // url:'pages/base/log/index', describe:'录音开始' }, { name:'stopRecord', // url:'pages/base/canlUse/index', describe:'停止录音' }, { name:'chooseVideo', // url:'pages/base/canlUse/index', describe:'选择视频' }, { name:'chooseImage', // url:'pages/base/log/index', describe:'选择图片' }, { name:'previewImage', // url:'pages/base/canlUse/index', describe:'预览图片' }, { name:'previewVideo', // url:'pages/base/log/index', describe:'预览视频' }, { name:'compressImage', // url:'pages/base/canlUse/index', describe:'图片压缩' }, { name:'getImageMetaData', // url:'pages/base/log/index', describe:'获取图片原始数据' }, { name:'stopAudio', // url:'pages/base/canlUse/index', describe:'停止录音播放' }, { name:'pauseAudio', // url:'pages/base/log/index', describe:'暂停录音播放' }, { name:'saveImageToPhotosAlbum', // url:'pages/base/canlUse/index', describe:'保存图片到相册' }, { name:'saveVideoToPhotosAlbum', // url:'pages/base/log/index', describe:'保存视频到相册' }, { name:'getVideoDetails', // url:'pages/base/canlUse/index', describe:'获取视频原始数据' }, { name:'chooseAlbumVideo', // url:'pages/base/log/index', describe:'选择视频' }, { name:'seek', // url:'pages/base/canlUse/index', describe:'快进' }, { name:'loop', // url:'pages/base/log/index', describe:'循环播放' }, { name:'setCallback', // url:'pages/base/canlUse/index', describe:'获取视频播放回调' }, { name:'getDuration', // url:'pages/base/log/index', describe:'获取视频时长' }, { name:'play', // url:'pages/base/log/index', describe:'播放录音' }, { name:'stop', // url:'pages/base/canlUse/index', describe:'停止录音播放' }, { name:'pause', // url:'pages/base/log/index', describe:'暂停录音播放' }, { name:'convertLocalImageToBase64', // url:'pages/base/canlUse/index', describe:'转换本地图片成base64数据' }, { name:'recordVideo', // url:'pages/base/log/index', describe:'录制视频' }, ] }, goRouter(url){ router.push({ uri: url, }) }, /** * @description: 扫码 * @param {*} * @return {*} */ scanCode(){ prompt.showToast({ message: '接口调用', duration: 200, }) this.$app.$def.bridge.scanCode(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 分享 * @param {*} * @return {*} */ openShare(){ const params = { text: 'share Text', imageUrl: '../../../assets/images/logo.png', url: 'http://www.baidu.com' } this.$app.$def.bridge.openShare(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 播放录音 * @param {*} * @return {*} */ playAudio(){ const params = { url: 'Sounds/20200827x.wav', loop: false } this.$app.$def.bridge.playAudio(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 开始录音 * @param {*} * @return {*} */ startRecord(){ const params = { path: "Sounds/20200827x.wav", maxTime: 600 } this.$app.$def.bridge.startRecord(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 停止录音 * @param {*} * @return {*} */ stopRecord(){ this.$app.$def.bridge.stopRecord() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 选择视频(此接口已废弃) * @param {*} * @return {*} */ chooseVideo(){ let params = { limitCount: 1, limitSize: '40960', type: 'mp4', videoDuration: '60', //选择视频时长 默认60秒 } this.$app.$def.bridge.chooseVideo(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 选择图片 * @param {*} * @return {*} */ chooseImage(){ let params = { count: 9, sizeType: 'compressed', sourceType: 'album', } this.$app.$def.bridge.chooseImage(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 预览图片 * @param {*} * @return {*} */ previewImage(){ let params = { urls: [ 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2Fc2c77cc783007737e782d0dc299c4fcf9005307b.jpg&refer=http%3A%2F%2Fi0.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1640745210&t=2ace9bb35ba945574149948ee8d8c0b4', 'https://pics1.baidu.com/feed/d01373f082025aaf71e440623f1be762014f1a45.jpeg?token=b9fae53a05d7f15cf711c37154c78af8&s=6D70178E808200F43428AF290300E052', ], showSavetoAlbum: true, } this.$app.$def.bridge.previewImage(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 预览视频 * @param {*} * @return {*} */ previewVideo(){ let params = { urls: ["./test.mp4"]} this.$app.$def.bridge.previewVideo(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 图片压缩 * @param {*} * @return {*} */ compressImage(){ let params = { src: './logo.png', // 只支持本地 图片 quality: 60, target: 'h5', } this.$app.$def.bridge.compressImage(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取图片原始数据 * @param {*} * @return {*} */ getImageMetaData(){ let params = { src: './logo.png', // 只支持本地 图片 } this.$app.$def.bridge.getImageMetaData(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 停止录音播放 * @param {*} * @return {*} */ stopAudio(){ this.$app.$def.bridge.stopAudio() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 暂停音频 * @param {*} * @return {*} */ pauseAudio(){ this.$app.$def.bridge.pauseAudio() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 保存图片到相册 * @param {*} * @return {*} */ saveImageToPhotosAlbum(){ const params={ base64:'iVBORw0KGgoAAAANSUhEUgAAALQAAAC0CAMAAAAKE/YAAAAAmVBMVEUAAADF7//F7//G8f/F7//E7//F7//F8P/////F7//F7//F7v/G8P/G7//L9P/L+f/P///F7//G7//G7//I8f/J7//F7v/F7//F7//F7//F7v/F7v/E8v/H7//E7v/E7v8yxf9Ozf9Byf84yP+Z4/9Tz/+p5/9x2P9d0f+67P+16v9n1f+i5f+F3f++7P+w6f+O3/9Gy/972v/N+3zjAAAAH3RSTlMAvH1C+/iulALr0cZWUBYNB+CPaTgu5drLn4lLJyDnlgL/DwAABcNJREFUeNrU1Eduw0AQRNGePMwUkxUo1v1vaXghwBsKDJP4TtCL30VOtWPJzUOzIr9lSmW3vGD6YXg5tpSiWvSG3bDqxkwvakpHU3U5Nsm7qqH4GvG8S+wg708R9fC20goHKF3FinwwGQ7LzEDBvfkPTvrhbwpp0HBCDxSKYHCGCQrhVcCp4kWe2TKHc3lpyaOxgBfFSL40nYQnsmvIi3KCR1NJ7s0MnrGZ3LJcwTvFLTlUMwTBanJGLAhkEc7SkAhGcnulNFwmIjIElp1OpFIITlV0Si8RgezpBI5IOB1lDaIxlg5pNSLS7aGbGaJiB662GpHp/YUYRGcusxsnNqRHEnraoZJIgqxoM6GQCCVoozpDMrKaNrEMCWH2OsOxc0JEIk/4IcWGoBckZqmvFfQn62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LFSv1xu4chs8A6KReWlSPhZoHJw7QiOpu9sV7Xwh6MvvCySiCg9ijHWVGkaMll6xoR40l52p+Tl9FO0rMT0+bGVkrQzsqbGZvQz/PBAKRoe8enRj3cDJE0QnXkErRjqKQiiIONA0dHHJFHEgTvIodMh+C4JUo4oZ2FETcRGFCqIzZv+gnXWzz205WuQlim4KALNpREpCVRZGFqd6dOPSde0HoWx6vH3v3otfiQwa0409ww5v4ZARRlt/ghU2d45yD2SG4YXcNZ1BtHpw1edrX5hFlk+eqbR4GN3mC3eSx+195d1ADAAwCQTCh32qof5l1QW7Aw8Fzx8wKmAGH3Fu806IkZv6FDO2YSSMyHmVmuuJmXXPTc2Tkz8wpmuFKMxEa8kJqQ/bWDAyTKWczmm3myc0QPJrcN3EDk5EwwQ6TRmmdyDu7uR8TVjIJKxQLQ1k2E8BDqUETdVT5TBQqRUlYFN9VmWMUlFbpbhZJb+foP2wWCmr7CcBVAAAAAElFTkSuQmCC', //图片的base64数据,优先级次之, } this.$app.$def.bridge.saveImageToPhotosAlbum(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 保存视频到相册 * @param {*} * @return {*} */ saveVideoToPhotosAlbum(){ const params={ src: '/localVideos/VIDEO_20210312_102126.mp4' } this.$app.$def.bridge.saveVideoToPhotosAlbum(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取视频原始数据 * @param {*} * @return {*} */ getVideoDetails(){ const params={ src: '/localVideos/VIDEO_20210312_102126.mp4' } this.$app.$def.bridge.getVideoDetails(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取视频原始数据 * @param {*} * @return {*} */ chooseAlbumVideo(){ const params={ limitCount: 1, limitSize: '40960', type: 'mp4', videoDuration: '60', //选择视频时长 默认60秒 } this.$app.$def.bridge.chooseAlbumVideo(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 快进 * @param {*} * @return {*} */ seek(){ const params=6000 this.$app.$def.bridge.seek(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 循环 * @param {*} * @return {*} */ loop(){ const params=true this.$app.$def.bridge.loop(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取视频播放回调 * @param {*} * @return {*} */ setCallback(){ this.$app.$def.bridge.setCallback((res)=>{ prompt.showToast({ message: res, duration: 200, }) },(err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取视频时长 * @param {*} * @return {*} */ getDuration(){ const params='/test_jack_record.wav' this.$app.$def.bridge.getDuration(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取视频时长 * @param {*} * @return {*} */ getDuration(){ const params='/test_jack_record.wav' this.$app.$def.bridge.getDuration(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取视频时长 * @param {*} * @return {*} */ getDuration(){ const params='/test_jack_record.wav' this.$app.$def.bridge.getDuration(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 播放录音 * @param {*} * @return {*} */ play(){ const params='/test_jack_record.wav' this.$app.$def.bridge.play(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 停止录音播放 * @param {*} * @return {*} */ stop(){ this.$app.$def.bridge.stop() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 暂停录音播放 * @param {*} * @return {*} */ pause(){ this.$app.$def.bridge.pause() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 转换本地图片成base64数据 * @param {*} * @return {*} */ convertLocalImageToBase64(){ const params = { "filePath": "" } this.$app.$def.bridge.convertLocalImageToBase64(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 转换本地图片成base64数据 * @param {*} * @return {*} */ recordVideo(){ const params = { "limitCount": 1, "limitSize":40960, "type":"mp4" } this.$app.$def.bridge.recordVideo(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, testBridge(name){ switch(name){ case 'scanCode': this.scanCode() break; case 'openShare': this.openShare() break; case 'playAudio': this.playAudio() break; case 'startRecord': this.startRecord() break; case 'stopRecord': this.stopRecord() break; case 'chooseVideo': this.chooseVideo() break; case 'chooseImage': this.chooseImage() break; case 'previewImage': this.previewImage() break; case 'previewVideo': this.previewVideo() break; case 'compressImage': this.compressImage() break; case 'getImageMetaData': this.getImageMetaData() break; case 'stopAudio': this.stopAudio() break; case 'pauseAudio': this.pauseAudio() break; case 'saveImageToPhotosAlbum': this.saveImageToPhotosAlbum() break; case 'saveVideoToPhotosAlbum': this.saveVideoToPhotosAlbum() break; case 'getVideoDetails': this.getVideoDetails() break; case 'chooseAlbumVideo': this.chooseAlbumVideo() break; case 'seek': this.seek() break; case 'loop': this.loop() break; case 'setCallback': this.setCallback() break; case 'getDuration': this.getDuration() break; case 'play': this.play() break; case 'stop': this.stop() break; case 'pause': this.pause() break; case 'convertLocalImageToBase64': this.convertLocalImageToBase64() break; case 'recordVideo': this.recordVideo() break; default: break; } } }