From b2efddc755d1b080e3f99da03ffbbb30682ea456 Mon Sep 17 00:00:00 2001 From: Jesse-Ma <24167796@qq.com> Date: Thu, 1 Dec 2022 16:36:26 +0800 Subject: [PATCH] big step --- .env | 0 .env.development | 4 + .env.production | 3 + package.json | 2 +- public/index.html | 5 +- src/App.vue | 4 +- src/api/note.js | 3 +- src/i18n/config/en.js | 11 ++- src/i18n/config/zh.js | 11 ++- src/main.js | 2 +- src/router/index.js | 79 ++++++++++++------- src/views/EditNote.vue | 8 +- src/views/ErrorView.vue | 17 ---- .../{BlankNote.vue => InvalidateNote.vue} | 6 ++ src/views/ViewNote.vue | 76 ++++++++++++++---- vue.config.js | 63 ++++++++------- 16 files changed, 190 insertions(+), 104 deletions(-) create mode 100644 .env create mode 100644 .env.development create mode 100644 .env.production delete mode 100644 src/views/ErrorView.vue rename src/views/{BlankNote.vue => InvalidateNote.vue} (95%) diff --git a/.env b/.env new file mode 100644 index 0000000..e69de29 diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..033cdd4 --- /dev/null +++ b/.env.development @@ -0,0 +1,4 @@ +NODE_ENV = developement +VUE_APP_BASE_NAME = developement +VUE_APP_BASE_URL = http://localhost:8080 + diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..8ce9cc0 --- /dev/null +++ b/.env.production @@ -0,0 +1,3 @@ +NODE_ENV = production +VUE_APP_BASE_NAME = production +VUE_APP_BASE_URL = https://flagnote.com diff --git a/package.json b/package.json index 2ea91b1..d2d1e53 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "serve": "vue-cli-service serve", - "build": "vue-cli-service build", + "build": "vue-cli-service build --mode production", "build.test": "vue-cli-service build --mode test", "build.production": "vue-cli-service build --mode production", "lint": "vue-cli-service lint" diff --git a/public/index.html b/public/index.html index a5a933b..f005dec 100644 --- a/public/index.html +++ b/public/index.html @@ -4,10 +4,11 @@ + @@ -16,6 +17,8 @@ + + diff --git a/src/App.vue b/src/App.vue index 9030bfc..3607c4b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -114,8 +114,8 @@ body { } button span { - font-size: 16px !important; + font-size: 15px !important; font-family: apple-system,BlinkMacSystemFont,Helvetica Neue,PingFang SC,Microsoft YaHei,Source Han Sans SC,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif; - margin-bottom: 5px; + margin-bottom: 6px; } diff --git a/src/api/note.js b/src/api/note.js index efed9a3..3335f20 100644 --- a/src/api/note.js +++ b/src/api/note.js @@ -3,8 +3,7 @@ import { getStoreKey } from "@/api/lock"; import storage from "@/libs/storage"; import { md5 } from "@/libs/secret"; -const servicePath = "https://flagnote.com"; -//const servicePath = "http://localhost:8080"; +const servicePath = process.env.VUE_APP_BASE_URL; export function saveNote(noteForm, secret) { let storeKey = secret.storeKey; diff --git a/src/i18n/config/en.js b/src/i18n/config/en.js index 4edfbcd..1cc7605 100644 --- a/src/i18n/config/en.js +++ b/src/i18n/config/en.js @@ -12,7 +12,16 @@ const en = { selectAll: "Select All", copy: "Copy", copyAll: "Copy All", - share: "Share" + share: "Share", + close: "Close" }, + error: { + "100001": "Unknown Error!", + "100002": "Wrong Address!", + "100003": "Deleted!", + "100004": "Expired!", + "100005": "Not Available!", + "100006": "100006", + } }; export default en; diff --git a/src/i18n/config/zh.js b/src/i18n/config/zh.js index 209bd61..da63767 100644 --- a/src/i18n/config/zh.js +++ b/src/i18n/config/zh.js @@ -12,7 +12,16 @@ const zh = { selectAll: "全选", copy: "复制", copyAll: "复制全部", - share: "分享" + share: "分享", + close: "关闭" }, + error: { + "100001": "未知错误!", + "100002": "地址有误!", + "100003": "内容已删除!", + "100004": "内容已过期!", + "100005": "内容不存在!", + "100006": "100006", + } }; export default zh; diff --git a/src/main.js b/src/main.js index 399b253..ebb5e46 100644 --- a/src/main.js +++ b/src/main.js @@ -6,7 +6,7 @@ import VueAxios from 'vue-axios' import './plugins/iview.js' import i18n from './i18n/' -axios.defaults.baseURL="https://flagnote.com"; +axios.defaults.baseURL= process.env.VUE_APP_BASE_URL; Vue.use(VueAxios, axios) diff --git a/src/router/index.js b/src/router/index.js index 75224b1..d42429c 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -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' }, ]; diff --git a/src/views/EditNote.vue b/src/views/EditNote.vue index 181058a..cd3c03d 100644 --- a/src/views/EditNote.vue +++ b/src/views/EditNote.vue @@ -100,7 +100,7 @@ @@ -163,12 +163,12 @@ - +

{{ $t("message.askTodelete") }}

-

@@ -423,6 +423,7 @@ export default { let storeInfo = storage.local.getText(that.secret.storeKey); let starray = storeInfo.split("|"); storage.local.setText(that.secret.storeKey, starray[0] + '|' + starray[1] + '|1|' + starray[3] + '|' + starray[4]); + storage.session.setText(that.secret.storeKey+"_share",'1'); location.reload(); this.state.locking = 0; } @@ -440,6 +441,7 @@ export default { dropNote() { this.model.deleting = true; storage.local.delete(this.secret.storeKey); + storage.session.setText(this.secret.storeKey+"_delete",1); location.reload(); }, bindToTopEvent() { diff --git a/src/views/ErrorView.vue b/src/views/ErrorView.vue deleted file mode 100644 index 362d248..0000000 --- a/src/views/ErrorView.vue +++ /dev/null @@ -1,17 +0,0 @@ - - - diff --git a/src/views/BlankNote.vue b/src/views/InvalidateNote.vue similarity index 95% rename from src/views/BlankNote.vue rename to src/views/InvalidateNote.vue index dcd6596..725ac64 100644 --- a/src/views/BlankNote.vue +++ b/src/views/InvalidateNote.vue @@ -37,6 +37,7 @@