From 75c29f8efdd67dcdcab4f4397aff1296c926c0a1 Mon Sep 17 00:00:00 2001 From: git-wlking Date: Tue, 19 Feb 2019 18:08:59 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0vuex=E5=92=8Caxioss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meta.js | 12 ++++++++++++ template/package.json | 4 +++- template/src/main.js | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/meta.js b/meta.js index a521f9bdd0..e0139dc42f 100644 --- a/meta.js +++ b/meta.js @@ -74,6 +74,16 @@ module.exports = { type: 'confirm', message: 'Install vue-router?', }, + axios: { + when: 'isNotTest', + type: 'confirm', + message: 'Install axios?', + }, + vuex: { + when: 'isNotTest', + type: 'confirm', + message: 'Install vuex?', + }, lint: { when: 'isNotTest', type: 'confirm', @@ -170,6 +180,8 @@ module.exports = { 'test/unit/setup.js': "unit && runner === 'jest'", 'test/e2e/**/*': 'e2e', 'src/router/**/*': 'router', + 'src/store/**/*': 'vuex', + 'src/api/**/*': 'axios', }, complete: function(data, { chalk }) { const green = chalk.green diff --git a/template/package.json b/template/package.json index 207322b98c..032f4a9aa7 100644 --- a/template/package.json +++ b/template/package.json @@ -26,7 +26,9 @@ }, "dependencies": { "vue": "^2.5.2"{{#router}}, - "vue-router": "^3.0.1"{{/router}} + "vue-router": "^3.0.1"{{/router}}{{#axios}}, + "axios": "^0.18.0"{{/axios}} {{#vuex}}, + "vuex": "^2.4.1"{{/vuex}} }, "devDependencies": { {{#lint}} diff --git a/template/src/main.js b/template/src/main.js index 48833b5ab7..eca09f6bbc 100644 --- a/template/src/main.js +++ b/template/src/main.js @@ -7,15 +7,28 @@ import App from './App' {{#router}} import router from './router' {{/router}} +{{#vuex}} +import store from './store' +{{/vuex}} +{{#axios}} +import axiosPlugin from './api' +{{/axios}} Vue.config.productionTip = false +{{#axios}} +Vue.use(axiosPlugin) +{{/axios}} + /* eslint-disable no-new */ new Vue({ el: '#app', {{#router}} router, {{/router}} + {{#vuex}} + store, + {{/vuex}} {{#if_eq build "runtime"}} render: h => h(App) {{/if_eq}} From e1cea98dd45e50ce521d87bb33a022298fd49a90 Mon Sep 17 00:00:00 2001 From: git-wlking Date: Tue, 19 Feb 2019 18:21:04 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/src/api/index.js | 70 +++++++++++++++++++++++++++++++++ template/src/store/State.js | 8 ++++ template/src/store/action.js | 0 template/src/store/index.js | 15 +++++++ template/src/store/mutations.js | 6 +++ 5 files changed, 99 insertions(+) create mode 100644 template/src/api/index.js create mode 100644 template/src/store/State.js create mode 100644 template/src/store/action.js create mode 100644 template/src/store/index.js create mode 100644 template/src/store/mutations.js diff --git a/template/src/api/index.js b/template/src/api/index.js new file mode 100644 index 0000000000..7d7a9b260c --- /dev/null +++ b/template/src/api/index.js @@ -0,0 +1,70 @@ +/* + * @Author: luox-e + * @Date: 2019-02-19 14:29:36 + * @Last Modified by: glodon + * @Last Modified time: 2019-02-19 14:43:08 + */ +import axios from 'axios' +import { + MessageBox +} from 'element-ui' + +let api = '/api' +if (process.env.NODE_ENV === 'development') { + api = '/api/' +} + +const baseURL = api +const Axios = axios.create({ + baseURL: baseURL, // 因为我本地做了反向代理 + headers: { + 'Content-Type': 'application/json;charset=utf-8' + } +}) +Axios.interceptors.response.use( + function (response) { + // 返回响应时做一些处理 + if ( + response.request.responseURL && + response.request.responseURL.indexOf( + 'Services/Identification/Server/login.ashx' + ) > 0 + ) { + this.$router.push({ + path: '/login' + }) + // window.location = '/Services/Identification/Server/Login.aspx' + } else { + if (response) { + return response.data + } else { + const msgConfig = { + title: '系统错误', + message: response.data.ResultDetailMsg + } + MessageBox(msgConfig) + } + } + }, + function (error) { + if (error.response) { + // const msgConfig = { + // title: '请求错误', + // message: error.response.status + // } + // MessageBox(msgConfig) + } + // 当响应异常时做一些处理 + return Promise.reject(error) + } +) + +// 对axios的实例重新封装成一个plugin ,方便 Vue.use(xxxx) +export default { + install: function (Vue, Option) { + Object.defineProperty(Vue.prototype, '$http', { + value: Axios + }) + }, + baseURL +} diff --git a/template/src/store/State.js b/template/src/store/State.js new file mode 100644 index 0000000000..c2c973f98a --- /dev/null +++ b/template/src/store/State.js @@ -0,0 +1,8 @@ +export default { + layoutConfig: { + colNum: 120, + rowHeight: 10, + margin: [0, 0] + }, + currentProtal: localStorage.getItem('currentPortal') ? JSON.parse(localStorage.getItem('currentPortal')) : {} +} diff --git a/template/src/store/action.js b/template/src/store/action.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/template/src/store/index.js b/template/src/store/index.js new file mode 100644 index 0000000000..1853e2cb9e --- /dev/null +++ b/template/src/store/index.js @@ -0,0 +1,15 @@ +import Vue from 'vue' +import Vuex from 'vuex' +import state from './State.js' +import mutations from './mutations.js' + + Vue.use(Vuex) + +export default new Vuex.Store({ + state, + mutations, + modules: { + + }, + strict: process.env.NODE_ENV !== 'production' // 严格模式 +}) diff --git a/template/src/store/mutations.js b/template/src/store/mutations.js new file mode 100644 index 0000000000..c1f68d93f8 --- /dev/null +++ b/template/src/store/mutations.js @@ -0,0 +1,6 @@ +export default { + updateCurrentProtal(state, currentProtal) { + state.currentProtal = currentProtal + localStorage.setItem('currentPortal', JSON.stringify({...currentProtal})) + } +} From e87136b66cb03e36d886e7f6e23d590894d3e23f Mon Sep 17 00:00:00 2001 From: git-wlking Date: Tue, 19 Feb 2019 18:49:09 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy-docs.sh | 2 +- template/src/App.vue | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy-docs.sh b/deploy-docs.sh index a9f76366a4..360e6f9dc0 100644 --- a/deploy-docs.sh +++ b/deploy-docs.sh @@ -5,4 +5,4 @@ cd _book git init git add -A git commit -m 'update book' -git push -f git@github.com:vuejs-templates/webpack.git master:gh-pages +git push -f git@github.com:git-wlking/VUT.git master:git-wlking diff --git a/template/src/App.vue b/template/src/App.vue index 0156030e49..b0ae090027 100644 --- a/template/src/App.vue +++ b/template/src/App.vue @@ -1,6 +1,7 @@