Skip to content

Commit

Permalink
chore: enhance iOS experience
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Apr 16, 2024
1 parent 0e537dc commit 89418de
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 40 deletions.
15 changes: 11 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<!-- /应用栏 -->
<!-- 抽屉 -->
<div id="app-drawer" class="mdui-drawer mdui-drawer-close mdui-hidden-sm-up">
<div class="app-drawer-logo" @touchend="enterDebugMode">Arknights<br />Toolbox</div>
<div class="app-drawer-logo" @click="enterDebugMode">Arknights<br />Toolbox</div>
<div class="mdui-list mdui-p-t-0">
<router-link
v-for="{ path, name } in routes.filter(({ name }) => name in routeMeta)"
Expand Down Expand Up @@ -199,7 +199,7 @@ import PasteCapturer from '@/components/PasteCapturer.vue';
import ScrollToTop from '@/components/ScrollToTop.vue';
import MigrationDialog from './components/home/MigrationDialog.vue';
import { router, meta as routeMeta } from './router';
import { VConsoleLoaded, loadVConsole } from '@/utils/vConsole';
import { vConsoleLoaded, loadVConsole } from '@/utils/vConsole';
import MduiTab from '@/utils/MduiTab';
import { IS_DEV } from '@/utils/env';
import { mapState } from 'pinia';
Expand Down Expand Up @@ -242,9 +242,9 @@ export default defineComponent({
document.getElementById('wrapper').scroll(0, 0);
},
enterDebugMode() {
if (VConsoleLoaded()) return;
if (vConsoleLoaded()) return;
this.debugClickCount++;
if (this.debugClickCount === 10) loadVConsole();
if (this.debugClickCount === 5) loadVConsole();
},
changeServer() {
if (this.nextServer === null) return;
Expand All @@ -264,6 +264,12 @@ export default defineComponent({
},
mounted() {
mduiTab.init();
this.$$('#app-drawer').on('close.mdui.drawer', () => {
this.debugClickCount = 0;
});
},
beforeDestroy() {
this.$$('#app-drawer').off('close.mdui.drawer');
},
});
</script>
Expand Down Expand Up @@ -319,6 +325,7 @@ html,
body {
height: 100%;
overflow: hidden;
touch-action: manipulation;
}
body {
box-sizing: border-box;
Expand Down
12 changes: 7 additions & 5 deletions src/components/DataImg.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<img
v-show="!(hideWhenError && isError)"
:src="imgSrc"
:style="imgStyle"
:loading="lazy ? 'lazy' : undefined"
Expand All @@ -14,7 +13,6 @@ import { defineComponent } from 'vue';
import { mapState } from 'pinia';
import { useHotUpdateStore } from '@/store/hotUpdate';
import { PNG1P } from '@/utils/constant';
import NO_IMAGE from '@/assets/img/no-image.png';
const defaultErrorStyle = {
backgroundColor: '#bdbdbd',
Expand All @@ -27,7 +25,6 @@ export default defineComponent({
type: String,
name: [Number, String],
errorStyle: [Boolean, Object],
hideWhenError: Boolean,
lazy: Boolean,
},
data: () => ({
Expand All @@ -41,14 +38,19 @@ export default defineComponent({
computed: {
...mapState(useHotUpdateStore, ['dataBaseURL']),
imgSrc() {
if (!(this.type && this.name)) return PNG1P;
if (this.isError && !this.hideWhenError) return NO_IMAGE;
if (!(this.dataBaseURL && this.type && this.name)) return PNG1P;
return `${this.dataBaseURL}/img/${this.type}/${this.name}.png`;
},
imgStyle() {
if (!this.isError) return;
return this.errorStyle === true ? defaultErrorStyle : this.errorStyle;
},
},
methods: {
handleError(e) {
console.error('[DataImg] loading error', this.imgSrc);
console.error(e);
},
},
});
</script>
30 changes: 6 additions & 24 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,30 +332,12 @@ new Vue({
nls.setItem('server', this.server);
} else this.server = server;

// 禁止 iOS 缩放
(() => {
document.addEventListener(
'touchstart',
event => {
if (event.touches.length > 1) {
event.preventDefault();
}
},
{ passive: false },
);
let lastTouchEnd = 0;
document.addEventListener(
'touchend',
event => {
const now = Date.now();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
},
false,
);
})();
// 禁止 iOS 双指缩放
document.addEventListener('gesturestart', function (event) {
event.preventDefault();
});
// 配合 touch-action: manipulation; 禁止 iOS 双击缩放
document.body.addEventListener('click', () => {});

// 初始化工具箱数据
this.initData();
Expand Down
8 changes: 4 additions & 4 deletions src/store/hotUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const DataStatus = {
};

export const useHotUpdateStore = defineStore('hotUpdate', () => {
const baseURL = ref(process.env.VUE_APP_DATA_BASE_URL?.replace(/\/$/, '') || '/data');
const baseURL = process.env.VUE_APP_DATA_BASE_URL?.replace(/\/$/, '') || '/data';
const mapMd5 = ref('');
const timestamp = ref(0);
const version = ref('');
Expand Down Expand Up @@ -139,7 +139,7 @@ export const useHotUpdateStore = defineStore('hotUpdate', () => {

try {
dataStatus.value = DataStatus.CHECKING;
const check = await fetchData(`${baseURL.value}/check.json`);
const check = await fetchData(`${baseURL}/check.json`);

if (!check.version.startsWith(CUR_VERSION)) {
throw new Error(i18n.t('hotUpdate.error.appNeedUpdate'));
Expand All @@ -158,7 +158,7 @@ export const useHotUpdateStore = defineStore('hotUpdate', () => {
downloadedDataNum.value = 0;
totalDataNum.value = 0;

const newMapMd5 = await fetchData(`${baseURL.value}/map.${check.mapMd5}.json`);
const newMapMd5 = await fetchData(`${baseURL}/map.${check.mapMd5}.json`);
const needUpdateUrlMap = getDataUrlMap(
_.pickBy(
newMapMd5,
Expand Down Expand Up @@ -232,7 +232,7 @@ export const useHotUpdateStore = defineStore('hotUpdate', () => {
};

const getDataUrl = (key, md5 = md5Map.value[key]) => {
return `${baseURL.value}/${key}`.replace(/\.[^.]+$/, `.${md5}$&`);
return `${baseURL}/${key}`.replace(/\.[^.]+$/, `.${md5}$&`);
};

const getDataUrlMap = targetMap => _.mapValues(targetMap, (md5, key) => getDataUrl(key, md5));
Expand Down
4 changes: 2 additions & 2 deletions src/utils/vConsole.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const VConsoleLoaded = () => !!window.VConsole;
export const vConsoleLoaded = () => !!window.VConsole;

export const loadVConsole = async () => {
if (VConsoleLoaded()) return;
if (vConsoleLoaded()) return;
await import(
/* webpackIgnore: true */ 'https://fastly.jsdelivr.net/npm/[email protected]/dist/vconsole.min.js'
);
Expand Down
2 changes: 1 addition & 1 deletion src/views/Material/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ export default defineComponent({
},
);

this.$$(dialog.$dialog[0]).on('close.mdui.dialog', () => {
this.$$(dialog.$dialog[0]).one('close.mdui.dialog', () => {
if (dropFocus) this.showDropDetail({ name: dropFocus });
});

Expand Down

0 comments on commit 89418de

Please sign in to comment.