You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.6 KiB
73 lines
1.6 KiB
|
3 years ago
|
/**
|
||
|
|
* 显示菜单
|
||
|
|
*/
|
||
|
|
function showMenu() {
|
||
|
|
const prompt = require('@system.prompt')
|
||
|
|
const router = require('@system.router')
|
||
|
|
const appInfo = require('@system.app').getInfo()
|
||
|
|
prompt.showContextMenu({
|
||
|
|
itemList: ['保存桌面', '关于', '取消'],
|
||
|
|
success: function(ret) {
|
||
|
|
switch (ret.index) {
|
||
|
|
case 0:
|
||
|
|
// 保存桌面
|
||
|
|
createShortcut()
|
||
|
|
break
|
||
|
|
case 1:
|
||
|
|
// 关于
|
||
|
|
router.push({
|
||
|
|
uri: '/About',
|
||
|
|
params: {
|
||
|
|
name: appInfo.name,
|
||
|
|
icon: appInfo.icon
|
||
|
|
}
|
||
|
|
})
|
||
|
|
break
|
||
|
|
case 2:
|
||
|
|
// 取消
|
||
|
|
break
|
||
|
|
default:
|
||
|
|
prompt.showToast({
|
||
|
|
message: 'error'
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 创建桌面图标
|
||
|
|
* 注意:使用加载器测试`创建桌面快捷方式`功能时,请先在`系统设置`中打开`应用加载器`的`桌面快捷方式`权限
|
||
|
|
*/
|
||
|
|
function createShortcut() {
|
||
|
|
const prompt = require('@system.prompt')
|
||
|
|
const shortcut = require('@system.shortcut')
|
||
|
|
shortcut.hasInstalled({
|
||
|
|
success: function(ret) {
|
||
|
|
if (ret) {
|
||
|
|
prompt.showToast({
|
||
|
|
message: '已创建桌面图标'
|
||
|
|
})
|
||
|
|
} else {
|
||
|
|
shortcut.install({
|
||
|
|
success: function() {
|
||
|
|
prompt.showToast({
|
||
|
|
message: '成功创建桌面图标'
|
||
|
|
})
|
||
|
|
},
|
||
|
|
fail: function(errmsg, errcode) {
|
||
|
|
prompt.showToast({
|
||
|
|
message: `${errcode}: ${errmsg}`
|
||
|
|
})
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
export default {
|
||
|
|
showMenu,
|
||
|
|
createShortcut
|
||
|
|
}
|