From 8e9a7de3877d2d6b90202dc2c9c5338f302e80d5 Mon Sep 17 00:00:00 2001 From: aixianling Date: Mon, 30 May 2022 18:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/serve.js | 2 +- src/App.vue | 52 ++++++++++++++++++++++++++++++++++++------- src/common/axios.js | 15 ++++++------- src/manifest.json | 7 ++++++ src/pages/loading.vue | 35 +++++------------------------ src/pages/login.vue | 51 +++++++++++++++++++++++++++++++++--------- src/store/index.js | 9 ++++++-- 7 files changed, 112 insertions(+), 59 deletions(-) diff --git a/bin/serve.js b/bin/serve.js index f8734632..1db3957b 100644 --- a/bin/serve.js +++ b/bin/serve.js @@ -14,7 +14,7 @@ const getFileInfo = (app, file) => { if (/^App/.test(app.name)) { let {name, label} = app, path = app.path.replace(/.+[\\\/]([^\\\/]+)[\\\/]([^\\\/]+)$/g, `/apps/$1/$2`) - apps.list.push({id: name, name, label, path, libPath: file.replace(/\\/g, '/').replace(/^src(\/.+)\.vue/, '$1'), type: 'wxwork'}) + apps.list.push({id: file.replace(/\.\/?(vue)?/g, '')?.replace(/[\\\/]/g,'_'), name, label, path, libPath: file.replace(/\\/g, '/').replace(/^src(\/.+)\.vue/, '$1'), type: 'wxwork'}) } } const saveApps = app => { diff --git a/src/App.vue b/src/App.vue index 93f592f3..791ae746 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,6 +9,8 @@ export default { }, onLaunch: function () { this.repairWxSDK() + this.initLoginBtn() + this.getApps() }, onShow: function () { this.initWaterMarker() @@ -19,7 +21,7 @@ export default { ...mapState(['token', 'user']), }, methods: { - ...mapMutations(['initWaterMarker', 'logout', 'getConfig']), + ...mapMutations(['initWaterMarker', 'logout', 'getConfig', 'setApps']), goto(params, cb) { let {path: url, query: {app}} = this.$route params.query = {app, ...(params.query || {})} @@ -32,7 +34,28 @@ export default { }, repairWxSDK() { wx = jWeixin - } + }, + initLoginBtn() { + let btn = document.createElement("div") + btn.id = "__loginBtn" + btn.innerText = "登录" + btn.addEventListener("click", () => { + if (location.pathname == "/pages/login") { + return this.$u.toast("已在登录页!") + } else uni.navigateTo({url: "/pages/login?back=" + encodeURIComponent(location.href?.replace(location.origin, ""))}) + }) + document.body.appendChild(btn) + }, + getApps() { + this.setApps([]) + this.$http.post("/node/wechatapps/list", null, { + params: {size: 999, type: 'wxwork'} + }).then(res => { + if (res?.data) { + this.setApps(res.data.records) + } + }) + }, }, } @@ -51,13 +74,14 @@ uni-page-body { background: #f5f5f5; position: relative; } - .text-hover { - opacity: 0.7; - } - .bg-hover { - background: #eee; - } +.text-hover { + opacity: 0.7; +} + +.bg-hover { + background: #eee; +} div[bottom] { position: fixed; @@ -153,6 +177,18 @@ uni-button { } } +#__loginBtn { + position: fixed; + right: 16px; + top: 20px; + background-color: $uni-color-primary; + color: #fff; + padding: 8px 16px; + border-radius: 8px; + font-size: 24px; + box-shadow: 0 0 0.61538462em rgb(0 0 0 / 40%); +} + @keyframes mapWarn { 0% { transform: scale(.5); diff --git a/src/common/axios.js b/src/common/axios.js index d6940e8e..61c0c61e 100644 --- a/src/common/axios.js +++ b/src/common/axios.js @@ -13,16 +13,15 @@ instance.interceptors.request.use(config => { if (/AppCountryAlbum/.test(location.pathname)) { config.baseURL = '/aca' config.url = config.url.replace(/(app|auth|admin)\//, "api/") - } - if (/\/grid\//.test(location.pathname)) { + } else if (/\/node\//.test(config.url)) { + config.baseURL = '/ns' + } else if (/\/grid\//.test(location.pathname)) { config.baseURL = '/wangge' - } - if (/\/project\/police\//.test(location.pathname)) { + } else if (/\/project\/police\//.test(location.pathname)) { config.baseURL = '/hnjc' config.url = config.url.replace(/(app|auth|admin)\//, "api/") - } - if (sessionStorage.getItem("prj") == "saas") { - config.url = config.url.replace(/(app|auth|admin)\//, "api/") + } else if (sessionStorage.getItem("prj") == "saas") { + config.baseURL = '/online' } if (!config.withoutToken && store.state.token) { config.headers["Authorization"] = store.state.token @@ -50,7 +49,7 @@ instance.interceptors.response.use(res => { return res.data } else if (res.data.code == 401) { store.commit("logout"); - uni.navigateTo({url: "/pages/login"}) + uni.showToast({title: "请登录用户!"}) } else { console.error(res.data.msg || "请求失败!") return Promise.reject(res.data.msg) diff --git a/src/manifest.json b/src/manifest.json index b0477f7e..9484005e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -65,6 +65,13 @@ "^/wangge": "/" } }, + "/ns": { + "target": "http://192.168.1.87:12525", + "changeOrigin": true, + "pathRewrite": { + "^/ns": "/" + } + }, "/hnjc": { "target": "http://192.168.1.87:12001/", "changeOrigin": true, diff --git a/src/pages/loading.vue b/src/pages/loading.vue index c0f630ef..568edbb0 100644 --- a/src/pages/loading.vue +++ b/src/pages/loading.vue @@ -5,13 +5,12 @@ -
去登录
{{ op.label }}
- {{ app.name }} + {{ app.label }}({{ app.name }})
@@ -26,12 +25,12 @@ export default { components: {AiSelect, AiResult}, inject: ['root'], computed: { - ...mapState(['token', 'openUser', 'user']), + ...mapState(['token', 'openUser', 'user', 'apps']), appsList() { let {search, currentLib} = this return this.apps.filter(e => { - return (currentLib == "apps" && e.path.indexOf("project") > -1) || e.path.indexOf(currentLib) > -1 - }).filter(e => !!search ? e.name.indexOf(search) > -1 : true) || [] + return (currentLib == "apps" && e.libPath.indexOf("project") > -1) || e.libPath.indexOf(currentLib) > -1 + }).filter(e => !!search ? e.label.indexOf(search) > -1 : true) || [] }, currentApp() { return this.apps.find(e => e.key == this.$route.query.app) || {} @@ -40,7 +39,6 @@ export default { data() { return { result: {}, - apps: [], libs: [ {label: "通用版", dir: "apps"}, {label: "上架版", dir: "saas"}, @@ -50,42 +48,21 @@ export default { } }, methods: { - ...mapMutations(['logout']), + ...mapMutations(['logout', 'setApps']), ...mapActions(['agentSign']), handleGotoApp(app) { - uni.navigateTo({url: `${app.path}`}) - }, - handleLogin() { - uni.navigateTo({url: "./login"}) - }, - getApps() { - this.apps = [] - let applications = require.context('../', true, /\.(\/.+)\/App[^\/]+\.vue$/) - applications.keys().map(path => { - if (applications(path).default) { - let {name: key, appName: name} = applications(path).default - this.apps.push({key, name, path: path.replace(/^\.(.+).vue$/g, '$1')}) - } - }) + uni.navigateTo({url: `${app.libPath}`}) }, handleSwitchSystem() { - this.changeConfig() sessionStorage.setItem("prj", this.currentLib) - this.getApps() this.logout() }, - changeConfig() { - this.$http.defaults.baseURL = this.currentLib == "apps" ? "/lan" : - this.currentLib == "saas" ? "/online" : "/" - } }, onLoad() { this.currentLib = sessionStorage.getItem("prj") || "apps" - this.changeConfig() this.agentSign(this.$route.query) }, onShow() { - this.getApps() this.result = { tips: "欢迎进入开发应用", } diff --git a/src/pages/login.vue b/src/pages/login.vue index 5bff50df..066d76b9 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -1,31 +1,40 @@