This commit is contained in:
Jesse-Ma
2022-12-01 16:36:26 +08:00
parent 332f556d1d
commit b2efddc755
16 changed files with 190 additions and 104 deletions

View File

@@ -2,8 +2,7 @@ import Vue from "vue";
import VueRouter from "vue-router";
import EditNote from "@/views/EditNote.vue";
import ViewNote from "@/views/ViewNote.vue";
import ErrorView from "@/views/ErrorView.vue";
import BlankNote from "@/views/BlankNote.vue";
import InvalidateNote from "@/views/InvalidateNote.vue";
import { getKeyMeta, getNoteMeta } from "@/api/note";
import { getStoreKey } from "@/api/lock";
import storage from "@/libs/storage";
@@ -12,6 +11,7 @@ Vue.use(VueRouter);
var keyMeta = null;
var noteMeta = null;
var errorMeta = null;
function getKeyMetaParam() {
return keyMeta;
@@ -21,6 +21,10 @@ function getNoteMetaParam() {
return noteMeta;
}
function getErrorMetaParam() {
return errorMeta;
}
function getNoteView() {
let path = location.pathname;
let key = path.substring(1, path.length);
@@ -31,7 +35,8 @@ function getNoteView() {
let regKey = /^[abcdefhikmnopqstuvwxyz23456789]{16}$/;
if (!regKey.test(key)) {
return;
errorMeta = 100002;
return InvalidateNote;
}
if (keyMeta && keyMeta.key) {
@@ -42,29 +47,52 @@ function getNoteView() {
//set noteMeta
noteMeta = getNoteMeta(key);
//invalidated key
if (!noteMeta || !noteMeta.key) {
errorMeta = 100002;
return InvalidateNote;
}
//validated state
if (1 == noteMeta.state) {
return ViewNote;
}
//deleted
if (0 == noteMeta.state) {
let storeKey = getStoreKey(key);
let storeInfo = storage.local.getText(storeKey);
if (storeInfo) {
let starray = storeInfo.split("|");
let commitFlag = starray[2];
if (commitFlag == "1") {
//timeout and clear local
storage.local.delete(storeKey );
return BlankNote;
} else {
//secondEdit
return EditNote;
}
} else {
//uncommited or timeout
return BlankNote;
storage.local.delete(storeKey);
// user deleted
if (noteMeta.ttl > 0) {
errorMeta = 100003;
return InvalidateNote;
} else {// timeout
errorMeta = 100004;
return InvalidateNote;
}
}
// view in time
return ViewNote;
if (null == noteMeta.state) {
let storeKey = getStoreKey(key);
//if has storage , then edit
if (storage.local.getText(storeKey)) {
return EditNote;
} else {
//storage is empty
let df = storage.session.getText(storeKey + "_delete")
if (df) {//unsubmitted,user deleted.
errorMeta = 100003;
return InvalidateNote;
} else {//unsubmitted
errorMeta = 100005;
return InvalidateNote;
}
}
}
// other exception
errorMeta = 100001;
return InvalidateNote;
}
function getHomeRedirect() {
@@ -85,15 +113,10 @@ const routes = [
redirect: getHomeRedirect(),
},
{
path: "/error",
name: "error",
component: ErrorView,
},
{
path: "/:name([abcdefhikmnopqstuvwxyz23456789]{16})",
path: "/:name([a-z0-9]{16})",
name: "note",
component: getNoteView(),
meta: { keyMeta: getKeyMetaParam(), noteMeta: getNoteMetaParam() },
meta: { keyMeta: getKeyMetaParam(), noteMeta: getNoteMetaParam(), errorMeta: getErrorMetaParam() },
//alias:'/xxxx'
},
];