12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import app from "@system.app";
- import device from "@system.device";
- import prompt from "@system.prompt";
- import shortcut from "@system.shortcut";
- import router from "@system.router";
- const SHORT_CUT_FORBIDDEN_INFO = "User forbidden";
- // 获取设备信息
- const getDeviceInfo = () => {
- device.getDeviceId({
- success: (ret) => {
- console.log(ret)
- }
- })
- }
- //获取是否创建图标
- const getShortCut = (fn) =>{
- shortcut.hasInstalled({
- success: (ret) => {
- fn(ret);
- }
- })
-
- }
- // 判断用户是否创建图标
- const hasCreateShortCut = (isPayPage = false,fn) => {
- shortcut.hasInstalled({
- success: (ret) => {
- if (!ret) {
- shortcut.install({
- message: "添加【追书云】到桌面,方便下次阅读",
- success: () => {
- prompt.showToast("添加成功!");
- fn && fn(true);
- },
- fail: (code) => {
- if (code === SHORT_CUT_FORBIDDEN_INFO && !isPayPage) app.exit();
- }
- })
- }
- }
- })
- }
- // 右上角菜单点击
- const showMenu = () => {
- const appInfo = app.getInfo();
- prompt.showContextMenu({
- itemList: ["保存桌面", "关于", "取消"],
- success: function (ret) {
- switch (ret.index) {
- case 0:
- // 保存桌面
- hasCreateShortCut();
- break;
- case 1:
- // 关于
- router.push({
- uri: "/views/About",
- params: {
- name: appInfo.name,
- icon: appInfo.icon
- }
- });
- break;
- case 2:
- // 取消
- break;
- default:
- prompt.showToast({
- message: "错误"
- });
- }
- }
- });
- }
- export default {
- shortcut,
- getDeviceInfo,
- hasCreateShortCut,
- showMenu,
- getShortCut
- }
|