赵明涛
6 months ago
7 changed files with 163 additions and 16 deletions
-
6app/build.gradle
-
2app/src/main/assets/apps/__UNI__3B4D40B/www/app-service.js
-
2daemonlibrary/src/main/java/com/shihoo/daemon/Daemon_Uni.java
-
29daemonlibrary/src/main/java/com/shihoo/daemon/watchdog/DaemonHelper.java
-
4uniapp_project_code/src/pages/login/index.vue
-
62uniapp_project_code/src/pages/login/mixins/watchDogCompositionAPI.js
-
74uniapp_project_code/src/pages/login/mixins/watchDogOptionsAPI.js
2
app/src/main/assets/apps/__UNI__3B4D40B/www/app-service.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,62 @@ |
|||
// useWatchDog.js
|
|||
import { ref } from 'vue'; |
|||
|
|||
// #ifdef APP-PLUS
|
|||
const Daemon_Uni = uni.requireNativePlugin('Daemon_Uni'); |
|||
// #endif
|
|||
|
|||
export function useWatchDog() { |
|||
const isDaemonRun = ref(false); // 进程守护状态
|
|||
|
|||
// 异步函数来开启或关闭守护进程
|
|||
async function selectDaemon() { |
|||
const _arr = ["开启-进程守护", "关闭-进程守护"]; |
|||
uni.showActionSheet({ |
|||
itemList: _arr, |
|||
success: async (res) => { |
|||
const _sel = _arr[res.tapIndex]; |
|||
console.log('选中了第' + (res.tapIndex + 1) + '个按钮' + _sel); |
|||
|
|||
if (res.tapIndex === 0) { |
|||
await daemonRun(true); |
|||
} else { |
|||
await daemonRun(false); |
|||
} |
|||
|
|||
console.log("daemonRun", _sel, isDaemonRun.value); |
|||
}, |
|||
fail: (res) => { |
|||
console.log(res.errMsg); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
// 开启与关闭守护进程
|
|||
async function daemonRun(run) { |
|||
// #ifdef APP-PLUS
|
|||
if (run) { |
|||
Daemon_Uni.startWatchDog({ |
|||
"api_name": "", |
|||
}, (ret) => { |
|||
console.log(ret); |
|||
isDaemonRun.value = true; // 假设总是成功开启
|
|||
}); |
|||
} else { |
|||
Daemon_Uni.closeWatchDog({ |
|||
"api_name": "", |
|||
}, (ret) => { |
|||
console.log(ret); |
|||
// 同上,假设关闭总是成功
|
|||
isDaemonRun.value = false; |
|||
}); |
|||
} |
|||
// #endif
|
|||
} |
|||
|
|||
// 返回响应式数据和函数
|
|||
return { |
|||
isDaemonRun, |
|||
selectDaemon, |
|||
daemonRun, |
|||
}; |
|||
} |
@ -0,0 +1,74 @@ |
|||
// mixins/watchDog.js
|
|||
|
|||
// 离线人脸识别
|
|||
// #ifdef APP-PLUS
|
|||
const Daemon_Uni = uni.requireNativePlugin('Daemon_Uni'); |
|||
// #endif
|
|||
|
|||
import util from '@/utils/util'; |
|||
|
|||
export default { |
|||
data() { |
|||
return { |
|||
is_daemon_run: false, //进程守护状态
|
|||
} |
|||
}, |
|||
created() { |
|||
console.warn('Mixin watchDog.js!'); |
|||
}, |
|||
methods: { |
|||
|
|||
// 选择进程守护 开/关. 该函数为附带交互的进程守护开关选择
|
|||
async selectDaemon(){ |
|||
let that = this |
|||
let _arr = ["开启-进程守护","关闭-进程守护"]; |
|||
uni.showActionSheet({ |
|||
itemList:_arr, |
|||
success: async function (res) { |
|||
let _sel = _arr[res.tapIndex] |
|||
let _val = "" |
|||
console.log('选中了第' + (res.tapIndex + 1) + '个按钮' +_sel); |
|||
|
|||
if(res.tapIndex==0){ |
|||
let daemon_res = await that.daemonRun(true) |
|||
that.$nextTick(()=>{ |
|||
// that.globalData.localConfig.is_daemon_run = daemon_res
|
|||
that.is_daemon_run = daemon_res |
|||
}); |
|||
}else{ |
|||
let daemon_res = await that.daemonRun(false) |
|||
that.$nextTick(()=>{ |
|||
// that.globalData.localConfig.is_daemon_run = daemon_res
|
|||
that.is_daemon_run = daemon_res |
|||
}); |
|||
} |
|||
console.log("daemonRun",_sel,_val,that.is_daemon_run) |
|||
}, |
|||
fail: function (res) { |
|||
console.log(res.errMsg); |
|||
} |
|||
}) |
|||
}, |
|||
//开启与关闭保活
|
|||
daemonRun(run){ |
|||
// #ifdef APP-PLUS
|
|||
if(run){ |
|||
Daemon_Uni.startWatchDog({ |
|||
"api_name":"", |
|||
}, |
|||
(ret) => { |
|||
console.log(ret) |
|||
}) |
|||
}else{ |
|||
Daemon_Uni.closeWatchDog({ |
|||
"api_name":"", |
|||
}, |
|||
(ret) => { |
|||
console.log(ret) |
|||
}) |
|||
} |
|||
// #endif
|
|||
}, |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue