add hint message

This commit is contained in:
Vick Scarlet
2021-12-02 18:18:46 +08:00
parent a143feadaf
commit b5edabc104
4 changed files with 41 additions and 12 deletions

View File

@@ -124,6 +124,14 @@ export default ({
UI_Read: 'Copy',
UI_Write: 'Paste',
UI_CopySuccess: 'Copy to clipboard success',
UI_CopyFaild: 'Copy to clipboard faild',
UI_PasteSuccessDecodeSuccess: 'Load Success!',
UI_PasteSuccessDecodeFaild: 'Paste success, but load faild!',
UI_PasteFaildDecodeSuccess: 'Paste faild, use input load success!',
UI_PasteFaildDecodeFaild: 'Paste faild, use input load faild!',
UI_LoadSuccess: 'Load Success!',
UI_LoadFaild: 'Load Faild!',

View File

@@ -127,6 +127,14 @@ export default ({
UI_LoadSuccess: '读档成功!',
UI_LoadFaild: '读档失败!',
UI_CopySuccess: '成功复制存档到剪贴板',
UI_CopyFaild: '复制存档到剪贴板失败,请手动复制存档内容',
UI_PasteSuccessDecodeSuccess: '读档成功!',
UI_PasteSuccessDecodeFaild: '粘贴剪贴板存档内容成功,但剪贴板内容读档失败',
UI_PasteFaildDecodeSuccess: '粘贴剪贴板存档内容失败,使用输入的内容读档成功',
UI_PasteFaildDecodeFaild: '粘贴剪贴板存档内容失败,使用输入的内容读档失败',
M_NoRank: '别卷了,没有排行榜',
F_RemakeTimes: '已重开{0}次',

View File

@@ -38,15 +38,16 @@ globalThis.$$copy = async text => {
const result = await navigator.permissions.query({ name: "clipboard-write" })
if (result.state == "granted" || result.state == "prompt") {
navigator.clipboard.writeText(text)
return;
return true;
}
const input = document.createElement('input');
input.setAttribute('style', 'opacity: 0;');
document.body.appendChild(input);
input.value = text;
input.select();
document.execCommand("copy");
const r = document.execCommand("copy");
document.body.removeChild(input);
return r;
}
globalThis.$$read = async ()=>{
@@ -58,10 +59,10 @@ globalThis.$$read = async ()=>{
input.setAttribute('style', 'opacity: 0;');
document.body.appendChild(input);
input.focus();
document.execCommand("paste");
const r = document.execCommand("paste");
const text = input.value;
document.body.removeChild(input);
return text;
return r?text:r;
};
const core = new Life();

View File

@@ -5,13 +5,25 @@ export default class SaveLoad extends ui.view.SaveLoadUI {
await this.close();
$ui.switchView(UI.pages.MAIN);
});
this.btnRead.on(Laya.Event.CLICK, this,()=>$$copy(this.input.text = this.data));
this.btnRead.on(Laya.Event.CLICK, this, async ()=>{
const result = await $$copy(this.input.text = this.data);
$$event('message', [result? 'UI_CopySuccess': 'UI_CopyFaild']);
});
this.btnWrite.on(Laya.Event.CLICK, this, async ()=>{
const text = await $$read();
if(text) {
this.data = this.input.text = text;
if(text == false) {
this.data = [
this.input.text,
'UI_PasteFaildDecodeSuccess',
'UI_PasteFaildDecodeFaild'
];
} else {
this.data = this.input.text;
this.input.text = text;
this.data = [
text,
'UI_PasteSuccessDecodeSuccess',
'UI_PasteSuccessDecodeFaild'
];
}
});
@@ -40,7 +52,7 @@ export default class SaveLoad extends ui.view.SaveLoadUI {
const file = e.target.files[0];
if(!file) return;
const reader = new FileReader();
reader.onload = () => this.data = reader.result;
reader.onload = () => this.data = [reader.result];
reader.readAsText(file);
document.body.removeChild(file);
};
@@ -67,17 +79,17 @@ export default class SaveLoad extends ui.view.SaveLoadUI {
return JSON.stringify(data);
}
set data(v) {
set data([v, success = 'UI_LoadSuccess', faild = 'UI_LoadFaild']) {
try {
const data = JSON.parse(v);
for(const key in data)
localStorage.setItem(key, data[key]);
$$event('message', ['UI_LoadSuccess']);
$$event('message', [success]);
$ui.theme = $ui.theme;
this.btnClose.event(Laya.Event.CLICK);
} catch (e) {
console.error(e);
$$event('message', ['UI_LoadFaild']);
$$event('message', [faild]);
}
}
}