123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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 getAppInfo = () => {
- const appInfo = app.getInfo();
- return appInfo;
- }
- //获取设备明细
- const getAppDev = (fn) => {
- device.getInfo({
- success: (ret)=> {
- fn&&fn(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,
- getAppInfo,
- getAppDev
- }
|