启动页 推送
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
<view class="setting-item" @click="toggleNotification">
|
||||
<text class="setting-text">消息通知</text>
|
||||
<view class="setting-right">
|
||||
<text class="setting-status">已开启</text>
|
||||
<text class="setting-status">{{notice_on?'已':'未'}}开启</text>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
@@ -73,7 +73,7 @@
|
||||
<view class="setting-item" @click="clearCache">
|
||||
<text class="setting-text">清除缓存</text>
|
||||
<view class="setting-right">
|
||||
<text class="cache-size">1.39MB</text>
|
||||
<text class="cache-size">{{fileSizeString}}</text>
|
||||
<uni-icons type="right" size="20" color="#999"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
@@ -144,7 +144,13 @@
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import {
|
||||
onShow
|
||||
} from "@dcloudio/uni-app";
|
||||
import my_api from '@/api/my_api.js'
|
||||
const notice_on = ref(false)
|
||||
|
||||
const fileSizeString = ref("0B")
|
||||
// 返回上一页
|
||||
const goBack = () => {
|
||||
uni.navigateBack();
|
||||
@@ -159,6 +165,53 @@
|
||||
});
|
||||
};
|
||||
|
||||
const formatSize = () => {
|
||||
plus.cache.calculate(function(size) {
|
||||
let sizeCache = parseInt(size);
|
||||
if (sizeCache == 0) {
|
||||
fileSizeString.value = "0B";
|
||||
} else if (sizeCache < 1024) {
|
||||
fileSizeString.value = sizeCache + "B";
|
||||
} else if (sizeCache < 1048576) {
|
||||
fileSizeString.value = (sizeCache / 1024).toFixed(2) + "KB";
|
||||
} else if (sizeCache < 1073741824) {
|
||||
fileSizeString.value = (sizeCache / 1048576).toFixed(2) + "MB";
|
||||
} else {
|
||||
fileSizeString.value = (sizeCache / 1073741824).toFixed(2) + "GB";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const isNoticeOn = () => {
|
||||
// #ifdef APP-PLUS
|
||||
if (plus.os.name == "Android") {
|
||||
var main = plus.android.runtimeMainActivity();
|
||||
var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
|
||||
if (NotificationManagerCompat == null) {
|
||||
NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
|
||||
}
|
||||
var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
|
||||
notice_on.value = areNotificationsEnabled
|
||||
return areNotificationsEnabled;
|
||||
} else if (plus.os.name == "iOS") {
|
||||
var isIosOn = undefined;
|
||||
var types = 0;
|
||||
var app = plus.ios.invoke("UIApplication", "sharedApplication");
|
||||
var settings = plus.ios.invoke(app, "currentUserNotificationSettings");
|
||||
if (settings) {
|
||||
types = settings.plusGetAttribute("types");
|
||||
plus.ios.deleteObject(settings);
|
||||
} else {
|
||||
types = plus.ios.invoke(app, "enabledRemoteNotificationTypes");
|
||||
}
|
||||
plus.ios.deleteObject(app);
|
||||
isIosOn = 0 != types;
|
||||
notice_on.value = isIosOn
|
||||
return isIosOn;
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
const goToPage = (url) => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/webview/webview?url=' + url
|
||||
@@ -417,10 +470,41 @@ const appdownLoad = (url) => {
|
||||
content: '确定要清除缓存吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showToast({
|
||||
title: '缓存已清除',
|
||||
icon: 'none'
|
||||
});
|
||||
let os = plus.os.name;
|
||||
if (os == 'Android') {
|
||||
let main = plus.android.runtimeMainActivity();
|
||||
let sdRoot = main.getCacheDir();
|
||||
let files = plus.android.invoke(sdRoot, "listFiles");
|
||||
let len = files.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
let filePath = '' + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
|
||||
plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
|
||||
if (entry.isDirectory) {
|
||||
entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录
|
||||
uni.showToast({
|
||||
title: '缓存清理完成',
|
||||
duration: 2000
|
||||
});
|
||||
formatSize(); // 重新计算缓存
|
||||
}, function(e) {
|
||||
console.log(e.message)
|
||||
});
|
||||
} else {
|
||||
entry.remove();
|
||||
}
|
||||
}, function(e) {
|
||||
console.log('文件路径读取失败')
|
||||
});
|
||||
}
|
||||
} else { // ios暂时未找到清理缓存的方法,以下是官方提供的方法,但是无效,会报错
|
||||
plus.cache.clear(function() {
|
||||
uni.showToast({
|
||||
title: '缓存清理完成',
|
||||
duration: 2000
|
||||
});
|
||||
formatSize();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -473,6 +557,10 @@ const appdownLoad = (url) => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onShow(() => {
|
||||
isNoticeOn()
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user