From a11eb1116666ca8ffb592d607b0ecc11fc17ad11 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 9 Jun 2022 14:50:36 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=96=B0?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=9A=AE=E8=82=A4=E4=B8=8D=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/IndexController.php | 12 +++++++ resources/assets/js/App.vue | 40 ++++++++++++++++++------ resources/assets/js/functions/common.js | 12 +++++++ resources/assets/js/store/actions.js | 4 +-- resources/assets/js/store/state.js | 2 +- resources/views/setting.blade.php | 8 +++++ 6 files changed, 65 insertions(+), 13 deletions(-) create mode 100755 resources/views/setting.blade.php diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 4ddc4b7b9..a63e6cac6 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -235,6 +235,18 @@ class IndexController extends InvokeController ]; } + /** + * 设置语言和皮肤 + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + */ + public function setting__theme_language() + { + return view('setting', [ + 'theme' => Request::input('theme'), + 'language' => Request::input('language') + ]); + } + /** * 提取所有中文 * @return array|string diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index 52a0b4304..4683cedb2 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -22,8 +22,8 @@ - - + + @@ -51,8 +51,8 @@ export default { data() { return { routePath: null, - manifestUrl: null, - inter: null, + searchInter: null, + iframes: [], } }, @@ -62,19 +62,20 @@ export default { }, mounted() { - this.inter = setInterval(this.searchEnter, 1000); window.addEventListener('resize', this.windowSizeListener); window.addEventListener('scroll', this.windowScrollListener); + this.searchInter = setInterval(this.searchEnter, 1000); + this.synchThemeLanguage(); }, beforeDestroy() { - this.inter && clearInterval(this.inter); window.removeEventListener('resize', this.windowSizeListener); window.removeEventListener('scroll', this.windowScrollListener); + this.searchInter && clearInterval(this.searchInter); }, computed: { - ...mapState(['ws']), + ...mapState(['ws', 'themeMode']), }, watch: { @@ -131,6 +132,14 @@ export default { }, immediate: true }, + + themeMode() { + this.synchThemeLanguage(); + }, + + languageType() { + this.synchThemeLanguage(); + } }, methods: { @@ -193,7 +202,10 @@ export default { let {action, data} = args; this.$store.dispatch(action, data); }) - this.manifestUrl = $A.apiUrl("../manifest") + this.iframes.push({ + key: 'manifest', + url: $A.apiUrl("../manifest") + }) }, eeuiEvents() { @@ -226,7 +238,17 @@ export default { } } } - } + }, + + synchThemeLanguage() { + if (this.$Electron || this.$isEEUiApp) { + this.iframes = this.iframes.filter(({key}) => key != 'synchThemeLanguage') + this.iframes.push({ + key: 'synchThemeLanguage', + url: $A.apiUrl(`../setting/theme_language?theme=${this.themeMode}&language=${this.languageType}`) + }) + } + }, } } diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 4281a11eb..d63c6caa8 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -590,6 +590,18 @@ } }, + /** + * 获取文本长度 + * @param string + * @returns {number} + */ + stringLength(string) { + if (typeof string === "number" || typeof string === "string") { + return (string + "").length + } + return 0; + }, + /** * 获取数组长度(处理数组不存在) * @param array diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 4e03c2d20..ae7dd61ed 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -245,7 +245,7 @@ export default { } state.themeMode = mode; state.themeIsDark = $A.dark.isDarkEnabled(); - $A.setStorage("cacheThemeMode", mode); + window.localStorage['__theme:mode__'] = mode; }, /** @@ -493,7 +493,6 @@ export default { return new Promise(function (resolve) { try { const cacheLoginEmail = $A.getStorageString("cacheLoginEmail"); - const cacheThemeMode = $A.getStorageString("cacheThemeMode"); const cacheFileSort = $A.getStorageJson("cacheFileSort"); // window.localStorage.clear(); @@ -507,7 +506,6 @@ export default { $A.setStorage("cacheProjectParameter", state.cacheProjectParameter); $A.setStorage("cacheServerUrl", state.cacheServerUrl); $A.setStorage("cacheLoginEmail", cacheLoginEmail); - $A.setStorage("cacheThemeMode", cacheThemeMode); $A.setStorage("cacheFileSort", cacheFileSort); $A.setStorage("cacheTaskBrowse", state.cacheTaskBrowse); dispatch("saveUserInfo", $A.isJson(userInfo) ? userInfo : state.userInfo); diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index d51661260..05590d1a8 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -124,7 +124,7 @@ const stateData = { ], // 主题皮肤 - themeMode: $A.getStorageString("cacheThemeMode"), + themeMode: window.localStorage['__theme:mode__'], themeList: [ {name: '跟随系统', value: 'auto'}, {name: '明亮', value: 'light'}, diff --git a/resources/views/setting.blade.php b/resources/views/setting.blade.php new file mode 100755 index 000000000..18533748e --- /dev/null +++ b/resources/views/setting.blade.php @@ -0,0 +1,8 @@ +