UNPKG

minix-template

Version:

minix template

703 lines (699 loc) 15 kB
/* * @Description: * @Autor: tangsj * @Date: 2022-04-28 16:29:05 * @LastEditTime: 2022-05-23 16:08:54 */ import router from '@system.router' import prompt from '@system.prompt' import {commandInterfaceWrapper,globalEventModuleWrapper,customCommandInterface} from '../../../util' import bridge from '@minix-iot/jsbridge-sdk' export default { data: { baseList:[ { name:'changeVolume', // url:'pages/base/canlUse/index', describe:'调节音量' }, { name:'checkAndRequestPermission', // url:'pages/base/log/index', describe:'检查并请求相册权限、通知权限、定位权限、蓝牙权限(只针对ios)' }, { name:'getBatteryInfo', // url:"pages/base/getSystemInfo/index", describe:'获取手机电量' }, { name:'setKeepScreenOn', describe:'屏幕常亮' }, { name:'getScreenBrightness', // url:"pages/base/fireGlobalEvent/index", describe:'获取屏幕亮度' }, { name:'setScreenBrightness', // url:'pages/base/getPluginInfo/index', describe:'设置屏幕亮度' }, { name:'startCompass', describe:'罗盘监听' }, { name:'stopCompass ', describe:'停止罗盘监听' }, { name:'startGyroscope', describe:'陀螺仪监听' }, { name:'stopGyroscope', describe:'停止陀螺仪监听' }, { name:'startAccelerometer', describe:'加速计监听' }, { name:'stopAccelerometer', describe:'停止加速计监听' }, { name:'vibrateLong', describe:'使手机发生较长时间的振动(400ms)' }, { name:'vibrateShort', describe:'使手机发生较短时间的振动(15ms)' }, { name:'startDeviceMotionListening', describe:'设备方向监听' }, { name:'stopDeviceMotionListening', describe:'停止设备方向监听' }, { name:'getNetworkStatus', describe:'获取当前设备网络信息' }, { name:'vibrate', describe:'使手机发生震动' }, { name:'setIdleTimerDisabled', describe:'插件调用系统自动灭屏功能' }, { name:'getAppInfo', describe:'指明当前APP的版本号和环境' }, { name:'getAppNewVersion', describe:'返回版本号,有升级策略返回策略版本,没有返回当前版本' }, { name:'getElderMode', describe:'返是否为老人模式' }, { name:'upgradeApp', describe:'按升级策略进行升级' }, { name:'setBackHandle', describe:'设置是否监控安卓手机物理返回键功能' }, { name:'openNativeSystemSetting', describe:'打开指定的系统设置' }, ] }, goRouter(url){ router.push({ uri: url, }) }, /** * @description: 调节音量 * @param {*} * @return {*} */ changeVolume(){ const params = { "value": "0.5" } this.$app.$def.bridge.changeVolume(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 检查并请求相册权限、通知权限、定位权限、蓝牙权限(只针对ios) * @param {*} * @return {*} */ checkAndRequestPermission(){ const params = { "type": "NOTIFICATION", "needRequest": "1" } this.$app.$def.bridge.checkAndRequestPermission(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 获取手机电量 * @param {*} * @return {*} */ getBatteryInfo(){ this.$app.$def.bridge.getBatteryInfo() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: '接口调用失败', duration: 200, }) }) }, /** * @description: 屏幕常亮 * @param {*} * @return {*} */ setKeepScreenOn(){ const params = { keepScreenOn: true } this.$app.$def.bridge.setKeepScreenOn(params) .then((res)=>{ prompt.showToast({ message:"接口调用成功", duration: 200, }) }).catch((err)=>{ prompt.showToast({ message:err, duration: 200, }) }) }, /** * @description: 获取屏幕亮度 * @param {*} * @return {*} */ getScreenBrightness (){ this.$app.$def.bridge.getScreenBrightness() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 设置屏幕亮度 * @param {*} * @return {*} */ setScreenBrightness(){ const params = { value: 0.5 } this.$app.$def.bridge.setScreenBrightness(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 罗盘监听 * @param {*} * @return {*} */ startCompass(){ this.$app.$def.bridge.setScreenBrightness() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 停止罗盘监听 * @param {*} * @return {*} */ stopCompass(){ this.$app.$def.bridge.stopCompass() .then((res)=>{ prompt.showToast({ message:"接口调用成功", duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 陀螺仪监听 * @param {*} * @return {*} */ startGyroscope(){ this.$app.$def.bridge.startGyroscope() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 陀螺仪监听 * @param {*} * @return {*} */ stopGyroscope(){ this.$app.$def.bridge.stopGyroscope() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 加速计监听 * @param {*} * @return {*} */ startAccelerometer(){ this.$app.$def.bridge.startAccelerometer() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 停止加速计监听 * @param {*} * @return {*} */ stopAccelerometer(){ this.$app.$def.bridge.stopAccelerometer() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 使手机发生较长时间的振动(400ms) * @param {*} * @return {*} */ vibrateLong(){ this.$app.$def.bridge.vibrateLong() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description: 使手机发生较短时间的振动(15ms) * @param {*} * @return {*} */ vibrateShort(){ this.$app.$def.bridge.vibrateShort() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:设备方向监听 * @param {*} * @return {*} */ startDeviceMotionListening(){ this.$app.$def.bridge.startDeviceMotionListening() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:停止设备方向监听 * @param {*} * @return {*} */ stopDeviceMotionListening(){ this.$app.$def.bridge.stopDeviceMotionListening() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:获取当前设备网络信息 * @param {*} * @return {*} */ getNetworkStatus(){ this.$app.$def.bridge.getNetworkStatus() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:使手机发生震动 * @param {*} * @return {*} */ vibrate(){ const params = { "intensity": "3" } this.$app.$def.bridge.vibrate(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:原生APP定时60秒后重新开启系统自动屏灭的操作 * @param {*} * @return {*} */ setIdleTimerDisabled(){ this.$app.$def.bridge.setIdleTimerDisabled() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:指明当前APP的版本号和环境 * @param {*} * @return {*} */ getAppInfo(){ this.$app.$def.bridge.getAppInfo() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:返回版本号,有升级策略返回策略版本,没有返回当前版本 * @param {*} * @return {*} */ getAppNewVersion(){ this.$app.$def.bridge.getAppNewVersion() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:是否为老人模式 * @param {*} * @return {*} */ getElderMode(){ this.$app.$def.bridge.getElderMode() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:按升级策略进行升级,如跳转应用市场或者应用内下载,无升级策略返回异常信息 * @param {*} * @return {*} */ upgradeApp(){ this.$app.$def.bridge.upgradeApp() .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:设置是否监控安卓手机物理返回键功能(仅安卓) * @param {*} * @return {*} */ setBackHandle(){ const params = { "isMonitor": "on" } this.$app.$def.bridge.setBackHandle(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, /** * @description:设置是否监控安卓手机物理返回键功能(仅安卓) * @param {*} * @return {*} */ openNativeSystemSetting(){ const params = { } this.$app.$def.bridge.openNativeSystemSetting(params) .then((res)=>{ prompt.showToast({ message: res, duration: 200, }) }).catch((err)=>{ prompt.showToast({ message: err, duration: 200, }) }) }, testBridge(name){ switch(name){ case 'changeVolume': this.changeVolume() break; case 'checkAndRequestPermission': this.checkAndRequestPermission() break; case 'getBatteryInfo': this.getBatteryInfo() break; case 'setKeepScreenOn': this.setKeepScreenOn() break; case 'getScreenBrightness': this.getScreenBrightness() break; case 'setScreenBrightness': this.setScreenBrightness() break; case 'startCompass': this.startCompass() break; case 'stopCompass': this.stopCompass() break; case 'startGyroscope': this.startGyroscope() break; case 'stopGyroscope': this.stopGyroscope() break; case 'startAccelerometer': this.startAccelerometer() case 'stopAccelerometer': this.stopAccelerometer() break; case 'vibrateLong': this.vibrateLong() break; case 'vibrateShort': this.vibrateShort() case 'startDeviceMotionListening': this.startDeviceMotionListening() break; case 'stopDeviceMotionListening': this.stopDeviceMotionListening() break; case 'getNetworkStatus': this.getNetworkStatus() break; case 'vibrate': this.vibrate() break; case 'setIdleTimerDisabled': this.setIdleTimerDisabled() break; case 'getAppInfo': this.getAppInfo() break; case 'getAppNewVersion': this.getAppNewVersion() break; case 'getElderMode': this.getElderMode() break; case 'upgradeApp': this.upgradeApp() break; case 'setBackHandle': this.setBackHandle() break; case 'openNativeSystemSetting': this.openNativeSystemSetting() break; default: break; } } }