async way blocked :(
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios from "axios";
|
||||
import { getStoreKey } from "@/api/lock";
|
||||
import storage from "@/libs/storage";
|
||||
import { md5, wrap} from "@/libs/secret";
|
||||
import { md5, wrap } from "@/libs/secret";
|
||||
import NoteConstant from "@/libs/constants";
|
||||
|
||||
axios.interceptors.response.use(undefined, (err) => {
|
||||
@@ -17,10 +17,10 @@ axios.interceptors.response.use(undefined, (err) => {
|
||||
}
|
||||
});
|
||||
|
||||
export function saveNote(noteForm, secret) {
|
||||
export async function saveNote(noteForm, secret) {
|
||||
let storeKey = secret.storeKey;
|
||||
|
||||
let storeInfo = storage.local.getText(storeKey);
|
||||
const storeInfo = await storage.local.getText(storeKey);
|
||||
let starray = storeInfo.split("|");
|
||||
|
||||
if (starray[2] == "1") {
|
||||
@@ -71,14 +71,13 @@ export function saveNote(noteForm, secret) {
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteNote(key) {
|
||||
export async function deleteNote(key) {
|
||||
let storeKey = getStoreKey(key);
|
||||
let storeInfo = storage.local.getText(storeKey);
|
||||
const storeInfo = await storage.local.getText(storeKey);
|
||||
let note = {
|
||||
cipher: storeInfo.substring(2, 34),
|
||||
key: key,
|
||||
};
|
||||
|
||||
return axios({
|
||||
url: NoteConstant.servicePath + "/note/" + key + "/delete",
|
||||
method: "post",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getKeyMeta } from "@/api/note";
|
||||
import { getStoreKey } from "@/api/lock";
|
||||
import { wrap } from "@/libs/secret";
|
||||
import storage from "@/libs/storage";
|
||||
@@ -12,7 +11,7 @@ export function setStoreText(noteForm, state, secret) {
|
||||
storeText = wrap(text, secret.secretKey);
|
||||
}
|
||||
|
||||
storage.local.setText(
|
||||
return storage.local.setText(
|
||||
secret.storeKey,
|
||||
state.lock +
|
||||
"|" +
|
||||
@@ -26,8 +25,7 @@ export function setStoreText(noteForm, state, secret) {
|
||||
);
|
||||
}
|
||||
|
||||
export function setNewStoreText(noteForm) {
|
||||
let keyMeta =getKeyMeta();
|
||||
export function setNewStoreText(noteForm,keyMeta) {
|
||||
let storeKey = getStoreKey(keyMeta.key);
|
||||
|
||||
let text = noteForm.text;
|
||||
@@ -38,7 +36,7 @@ export function setNewStoreText(noteForm) {
|
||||
storeText = wrap(text, keyMeta.secretKey);
|
||||
}
|
||||
|
||||
storage.local.setText(
|
||||
return storage.local.setText(
|
||||
storeKey,
|
||||
"0|" +
|
||||
keyMeta.cipher +
|
||||
@@ -47,8 +45,6 @@ export function setNewStoreText(noteForm) {
|
||||
"|" +
|
||||
storeText
|
||||
);
|
||||
|
||||
return keyMeta.key;
|
||||
}
|
||||
|
||||
export function clearStoreText(key) {
|
||||
|
||||
@@ -31,7 +31,7 @@ class Session {
|
||||
|
||||
class Local {
|
||||
setObject(key, value) {
|
||||
localforage.setItem(key, JSON.stringify(value));
|
||||
return localforage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
getObject(key) {
|
||||
@@ -39,11 +39,11 @@ class Local {
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
localforage.removeItem(key);
|
||||
return localforage.removeItem(key);
|
||||
}
|
||||
|
||||
setText(key, value) {
|
||||
localforage.setItem(key, value);
|
||||
return localforage.setItem(key, value);
|
||||
}
|
||||
|
||||
getText(key) {
|
||||
|
||||
@@ -21,7 +21,14 @@ export function getRouter() {
|
||||
}
|
||||
|
||||
function returnEditViewRouter(keyMeta,noteMeta,errorMeta){
|
||||
let routes = composeRoutes(homeRedirect,noteView,keyMeta,noteMeta,errorMeta);
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
name: "home",
|
||||
redirect: homeRedirect,
|
||||
}
|
||||
];
|
||||
|
||||
let router = composeRouter(routes)
|
||||
|
||||
return new Promise((resolve) => {
|
||||
@@ -45,6 +52,17 @@ function composeRoutes(homeRedirect,noteView,keyMeta,noteMeta,errorMeta) {
|
||||
|
||||
function composeRouter(routes) {
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
name: "home",
|
||||
redirect: homeRedirect,
|
||||
}
|
||||
];
|
||||
|
||||
return routes;
|
||||
|
||||
|
||||
const router = new VueRouter({
|
||||
routes,
|
||||
mode: "history",
|
||||
|
||||
@@ -7,7 +7,7 @@ import storage from "@/libs/storage";
|
||||
import { getStoreKey } from "@/api/lock";
|
||||
|
||||
|
||||
export default function getRouter() {
|
||||
export default async function getRouter() {
|
||||
let path = location.pathname;
|
||||
let key = path.substring(1, path.length);
|
||||
//let errorMeta = null;
|
||||
@@ -18,6 +18,7 @@ export default function getRouter() {
|
||||
}
|
||||
|
||||
let keyMeta = storage.session.getObject("keyMeta");
|
||||
storage.session.delete("keyMeta");
|
||||
|
||||
let regKey = /^[abcdefhikmnopqstuvwxyz23456789]{16}$/;
|
||||
|
||||
@@ -31,7 +32,9 @@ export default function getRouter() {
|
||||
return noteRouter(EditNote, keyMeta, null);
|
||||
}
|
||||
|
||||
return getNoteMetaNew(key).then(function (resp) {
|
||||
let resp = await getNoteMetaNew(key);
|
||||
|
||||
|
||||
if (null == resp || null == resp.data) {
|
||||
return errorRouter(100006);
|
||||
}
|
||||
@@ -71,7 +74,8 @@ export default function getRouter() {
|
||||
//edit or unsubmitted
|
||||
if (null == noteMeta.state) {
|
||||
let storeKey = getStoreKey(key);
|
||||
return storage.local.getText(storeKey).then(function (storeInfo) {
|
||||
const storeInfo = await storage.local.getText(storeKey);
|
||||
|
||||
//if has storage , then edit
|
||||
if (null != storeInfo) {
|
||||
return noteRouter(EditNote, keyMeta, noteMeta);
|
||||
@@ -86,10 +90,8 @@ export default function getRouter() {
|
||||
// errorMeta = 100005;
|
||||
return errorRouter(100005);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return errorRouter(100001);
|
||||
}
|
||||
|
||||
function noteRouter(noteView, keyMeta, noteMeta) {
|
||||
@@ -113,7 +115,7 @@ function noteRouter(noteView, keyMeta, noteMeta) {
|
||||
function errorRouter(errorCode) {
|
||||
const routes = [
|
||||
{
|
||||
path: "/error_:code([0-9]{6})",
|
||||
path: "/:name([a-z0-9]{10,20})",
|
||||
name: "error",
|
||||
component: ErrorNote,
|
||||
errorMeta: errorCode
|
||||
|
||||
@@ -201,6 +201,7 @@ import { setStoreText,setNewStoreText } from "@/libs/noteStorage";
|
||||
import { saveAs } from 'file-saver';
|
||||
import { isWeixin } from "@/libs/utils";
|
||||
import NoteConstant from "@/libs/constants";
|
||||
import { getKeyMeta } from "@/api/note";
|
||||
|
||||
export default {
|
||||
name: 'EditNote',
|
||||
@@ -247,10 +248,10 @@ export default {
|
||||
let keyMeta = this.$route.meta.keyMeta;
|
||||
|
||||
//ipad chrome url not redirect
|
||||
let path = location.pathname;
|
||||
if ("/" == path) {
|
||||
history.pushState('', '', '/' + this.noteForm.key);
|
||||
}
|
||||
// let path = location.pathname;
|
||||
// if ("/" == path) {
|
||||
// history.pushState('', '', '/' + this.noteForm.key);
|
||||
// }
|
||||
|
||||
//wx does not show downloadText
|
||||
this.model.showDownloadText = !isWeixin();
|
||||
@@ -281,16 +282,20 @@ export default {
|
||||
let noteMeta = this.$route.meta.noteMeta;
|
||||
this.secret.secretKey = noteMeta.secretKey;
|
||||
|
||||
let storeInfo = storage.local.getText(storeKey);
|
||||
let that = this;
|
||||
|
||||
storage.local.getText(storeKey).then(function(storeInfo){
|
||||
let starray = storeInfo.split('|');
|
||||
this.state.lock = parseInt(starray[0]);
|
||||
this.secret.cipher = starray[1];
|
||||
this.state.initTime = parseInt(starray[3]);
|
||||
that.state.lock = parseInt(starray[0]);
|
||||
that.secret.cipher = starray[1];
|
||||
that.state.initTime = parseInt(starray[3]);
|
||||
|
||||
//draw text;
|
||||
if (starray[4]) {
|
||||
this.noteForm.text = unwrap(starray[4], this.secret.secretKey);
|
||||
that.noteForm.text = unwrap(starray[4], that.secret.secretKey);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
this.bindCtrlAllEvent();
|
||||
@@ -398,13 +403,10 @@ export default {
|
||||
setStoreText(this.noteForm, this.state, this.secret);
|
||||
|
||||
} else if (event.ctrlKey && (event.which == 13)) {
|
||||
//save
|
||||
|
||||
this.submitNote();
|
||||
}
|
||||
},
|
||||
save() {
|
||||
return saveNote(this.noteForm, this.secret);
|
||||
},
|
||||
validateForm() {
|
||||
let text = this.noteForm.text;
|
||||
if (text.length > NoteConstant.noteMaxCount) {
|
||||
@@ -433,25 +435,28 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
setStoreText(this.noteForm, this.state, this.secret);
|
||||
|
||||
this.model.submitting = true;
|
||||
|
||||
let that = this;
|
||||
this.save().then(res => {
|
||||
saveNote(this.noteForm, this.secret).then(res => {
|
||||
if (res.data && res.data.code == "000000") {
|
||||
storage.session.setText(that.secret.storeKey + "_share", '1');
|
||||
|
||||
that.state.commited = 1;
|
||||
setStoreText(this.noteForm, this.state, this.secret);
|
||||
|
||||
setStoreText(this.noteForm, this.state, this.secret).then(function(){
|
||||
location.reload();
|
||||
this.state.locking = 0;
|
||||
});
|
||||
} else {
|
||||
alert(res.data.code);
|
||||
this.model.submitting = false;
|
||||
this.state.locking = 0;
|
||||
if(res.data.code=="100013"||res.data.code=="800001"){
|
||||
let key = setNewStoreText(this.noteForm);
|
||||
location.href="/"+key;
|
||||
let keyMeta = getKeyMeta();
|
||||
setNewStoreText(this.noteForm,keyMeta).then(function () {
|
||||
location.href="/"+keyMeta.key;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -420,9 +420,13 @@ export default {
|
||||
|
||||
this.startClock();
|
||||
|
||||
storage.local.dynamicClear();
|
||||
|
||||
this.loadText();
|
||||
let that = this;
|
||||
storage.local.getText(this.secret.storeKey).then(function(storeInfo){
|
||||
that.loadText(storeInfo);
|
||||
});
|
||||
|
||||
storage.local.dynamicClear();
|
||||
|
||||
this.bindCtrlAllEvent();
|
||||
this.bindCopyUrlEvent();
|
||||
@@ -517,8 +521,9 @@ export default {
|
||||
that.state.ttl = that.state.initTtl - (new Date().getTime() - that.state.initTime);
|
||||
|
||||
if (that.state.ttl <= 0) {
|
||||
storage.local.delete(that.secret.storeKey);
|
||||
storage.local.delete(that.secret.storeKey).then(function(){
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
}, 1000)
|
||||
},
|
||||
@@ -554,8 +559,9 @@ export default {
|
||||
let that = this;
|
||||
deleteNote(this.noteForm.key).then(res => {
|
||||
if (res.data&&res.data.code=="000000") {
|
||||
storage.local.delete(that.secret.storeKey);
|
||||
storage.local.delete(that.secret.storeKey).then(function(){
|
||||
location.reload();
|
||||
});
|
||||
} else {
|
||||
that.model.deleting = false;
|
||||
}
|
||||
@@ -563,11 +569,9 @@ export default {
|
||||
alert(error);
|
||||
});
|
||||
},
|
||||
loadText() {
|
||||
loadText(storeInfo) {
|
||||
let that = this;
|
||||
|
||||
let storeInfo = storage.local.getText(this.secret.storeKey);
|
||||
|
||||
let starray = [];
|
||||
if (storeInfo) {
|
||||
starray = storeInfo.split('|');
|
||||
|
||||
Reference in New Issue
Block a user