From 45c2a89eeb04b3feb798ffb951efa00cf05429ce Mon Sep 17 00:00:00 2001 From: guorongsen <49149153+guorongsen@users.noreply.github.com> Date: Mon, 27 May 2019 20:28:14 +0800 Subject: [PATCH 1/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6b4fea47e6..b71d8dc8e7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# guors-goldenhome +> dudududududu # vue-webpack-boilerplate > A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction. From 53c9dd46dfc546b2e9cb5deffa780a3e7ef1cde9 Mon Sep 17 00:00:00 2001 From: guorongsen <49149153+guorongsen@users.noreply.github.com> Date: Mon, 27 May 2019 20:36:29 +0800 Subject: [PATCH 2/5] Update README.md --- template/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/template/README.md b/template/README.md index 4b0258a35b..df71d572cd 100644 --- a/template/README.md +++ b/template/README.md @@ -3,6 +3,7 @@ > {{ description }} ## Build Setup +# guorongsen ``` bash # install dependencies From b239fcaea35da4f656419f9f2904e4db178b3069 Mon Sep 17 00:00:00 2001 From: guorongsen <49149153+guorongsen@users.noreply.github.com> Date: Tue, 28 May 2019 09:35:35 +0800 Subject: [PATCH 3/5] Add files via upload --- template/src/assets/d-plus.png | Bin 0 -> 346 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 template/src/assets/d-plus.png diff --git a/template/src/assets/d-plus.png b/template/src/assets/d-plus.png new file mode 100644 index 0000000000000000000000000000000000000000..50f0b383c38489b64e1dfaeb460fdcce45eefa8c GIT binary patch literal 346 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7T#lEU{v&UaSW-L^Y*r4-eCig_Comu z2@4h&w7+KLVq-h2Q@`;F^A`?gYp4DoiGT~*JtDqcx1wfBtKN^VdgEI6(~^;m@1VqI z^QBXAy;epCO%2-Szt`phGjl;?1n+^D56>|>_Y@i*oo=%Hh=ln8(Hp&Hvi-;TA6zR~ zw~SFwb7|fdM+Qa~0S6GV;I2omasz`gGs8E_=gx<}rm=ruo+G_Zy@7#=<3g_)hXRNJ zBtjVu$XV=<*j~N&OUzrwSNj?5q8S}uD}9AhjTvz zsyD1W`Gz6N9cJGPH)){74W-O${#^>;P-IwM{do8KoxZWx_r2dg{}NN#`+YAgN^S2{ dCSRKwzomZGZthcNCBQIa@O1TaS?83{1OQgxe;fb+ literal 0 HcmV?d00001 From 955fa9882326389175aab1630f30f842ddded088 Mon Sep 17 00:00:00 2001 From: guorongsen <49149153+guorongsen@users.noreply.github.com> Date: Thu, 20 Jun 2019 15:16:36 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 日常更新 --- template/src/App.vue | 31 +++---- template/src/api/test.js | 16 ++++ template/src/components/HelloWorld.vue | 117 +++++++------------------ template/src/main.js | 40 ++++----- template/src/router/index.js | 30 ++++--- template/src/store/actions.js | 12 +++ template/src/store/getters.js | 8 ++ template/src/store/index.js | 24 +++++ template/src/store/mutations.js | 11 +++ template/src/utils/fetch.js | 88 +++++++++++++++++++ template/src/utils/validate.js | 35 ++++++++ 11 files changed, 279 insertions(+), 133 deletions(-) create mode 100644 template/src/api/test.js create mode 100644 template/src/store/actions.js create mode 100644 template/src/store/getters.js create mode 100644 template/src/store/index.js create mode 100644 template/src/store/mutations.js create mode 100644 template/src/utils/fetch.js create mode 100644 template/src/utils/validate.js diff --git a/template/src/App.vue b/template/src/App.vue index 0156030e49..ffda99645e 100644 --- a/template/src/App.vue +++ b/template/src/App.vue @@ -1,25 +1,27 @@ diff --git a/template/src/api/test.js b/template/src/api/test.js new file mode 100644 index 0000000000..fe46f90a61 --- /dev/null +++ b/template/src/api/test.js @@ -0,0 +1,16 @@ +import fetch from '../utils/fetch'; + +export function testRequest (id) { + return fetch({ + url: process.env.BASE_API + '/jeegoldenhome/jrest/goldenhomecrm/dictApi/getDictList?type=' + id, + method: 'get' + }); +} + +export function request (params) { + return fetch({ + url: process.env.BASE_API + '/grs/guors', + method: 'post', + data: params + }); +} diff --git a/template/src/components/HelloWorld.vue b/template/src/components/HelloWorld.vue index ce0edd8ac1..dd059b836c 100644 --- a/template/src/components/HelloWorld.vue +++ b/template/src/components/HelloWorld.vue @@ -1,97 +1,42 @@ diff --git a/template/src/main.js b/template/src/main.js index 48833b5ab7..478f0d06dc 100644 --- a/template/src/main.js +++ b/template/src/main.js @@ -1,26 +1,26 @@ -{{#if_eq build "standalone"}} // The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. -{{/if_eq}} -import Vue from 'vue' -import App from './App' -{{#router}} -import router from './router' -{{/router}} +import Vue from 'vue'; +import App from './App'; +import router from './router'; +import axios from 'axios'; +import store from './store'; +import { AlertPlugin, ToastPlugin, ConfirmPlugin, LoadingPlugin } from 'vux'; +Vue.use(AlertPlugin); +Vue.use(ToastPlugin); +Vue.use(ConfirmPlugin); +Vue.use(LoadingPlugin); -Vue.config.productionTip = false +Vue.prototype.$http = axios; +Vue.config.productionTip = false; + +console.log(process.env.BASE_API); /* eslint-disable no-new */ new Vue({ - el: '#app', - {{#router}} - router, - {{/router}} - {{#if_eq build "runtime"}} - render: h => h(App) - {{/if_eq}} - {{#if_eq build "standalone"}} - components: { App }, - template: '' - {{/if_eq}} -}) + el: '#app', + store, + router, + components: { App }, + template: '' +}); diff --git a/template/src/router/index.js b/template/src/router/index.js index 5fa7f9d319..b68ef548fa 100644 --- a/template/src/router/index.js +++ b/template/src/router/index.js @@ -1,15 +1,21 @@ -import Vue from 'vue' -import Router from 'vue-router' -import HelloWorld from '@/components/HelloWorld' +import Vue from 'vue'; +import Router from 'vue-router'; +import HelloWorld from '@/components/HelloWorld'; +import Test from '@/components/Test'; -Vue.use(Router) +Vue.use(Router); export default new Router({ - routes: [ - { - path: '/', - name: 'HelloWorld', - component: HelloWorld - } - ] -}) + routes: [ + { + path: '/', + name: 'HelloWorld', + component: HelloWorld + }, + { + path: '/Test', + name: 'Test', + component: Test + } + ] +}); diff --git a/template/src/store/actions.js b/template/src/store/actions.js new file mode 100644 index 0000000000..1ac53673af --- /dev/null +++ b/template/src/store/actions.js @@ -0,0 +1,12 @@ +const actions = { + changeName ({commit}, payload) { // 自定义触发mutations里函数的方法,context与store 实例具有相同方法和属性 + return new Promise((resolve, reject) => { + setTimeout(() => { + commit('CHANGE_NAME'); + resolve(); + }, 500); + }); + } +}; + +export default actions; diff --git a/template/src/store/getters.js b/template/src/store/getters.js new file mode 100644 index 0000000000..814651f3b8 --- /dev/null +++ b/template/src/store/getters.js @@ -0,0 +1,8 @@ +const getters = { + name: state => state.name, + age: state => state.age, + sex: (state, getters) => { + return getters.name + state.sex; + } +}; +export default getters; diff --git a/template/src/store/index.js b/template/src/store/index.js new file mode 100644 index 0000000000..259691f60a --- /dev/null +++ b/template/src/store/index.js @@ -0,0 +1,24 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import getters from './getters'; +import mutations from './mutations'; +import actions from './actions'; + +Vue.use(Vuex); + +const state = { + name: '1', + age: '', + sex: 'boy', + userInfo: { mobile: '12345678901' } +}; + +const store = new Vuex.Store({ + state, + getters, + mutations, + actions, + modules: {} +}); + +export default store; diff --git a/template/src/store/mutations.js b/template/src/store/mutations.js new file mode 100644 index 0000000000..9b38ada918 --- /dev/null +++ b/template/src/store/mutations.js @@ -0,0 +1,11 @@ +const mutations = { + CHANGE_NAME: (state, payload) => { + // return new Promise((resolve, reject) => { + // console.log(payload); + state.name++; + // resolve(); + // }); + } +}; + +export default mutations; diff --git a/template/src/utils/fetch.js b/template/src/utils/fetch.js new file mode 100644 index 0000000000..4ddd2635df --- /dev/null +++ b/template/src/utils/fetch.js @@ -0,0 +1,88 @@ +import axios from 'axios'; +// import { +// Message, +// MessageBox +// } from 'element-ui'; +// import store from '../store'; +// import { +// getToken +// } from 'utils/auth'; + +// 创建axios实例 +const service = axios.create({ + // baseURL: process.env.BASE_API, // api的base_url + timeout: 5000 // 请求超时时间 +}); + +// request拦截器 +service.interceptors.request.use(config => { + // // Do something before request is sent + // if (store.getters.token) { + // // 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改 + // config.headers['Authorization'] = getToken(); + // } + return config; +}, error => { + // Do something with request error + console.log(error); // for debug + Promise.reject(error); +}); + +// respone拦截器 +service.interceptors.response.use( + response => { + /** + * 下面的注释为通过response自定义code来标示请求状态,当code返回如下情况为权限有问题,登出并返回到登录页 + * 如通过xmlhttprequest 状态码标识 逻辑可写在下面error中 + */ + // const res = response.data; + return response.data; + // if (response.status === 401 || res.status === 40101) { + // MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', { + // confirmButtonText: '重新登录', + // cancelButtonText: '取消', + // type: 'warning' + // }).then(() => { + // store.dispatch('FedLogOut').then(() => { + // location.reload(); // 为了重新实例化vue-router对象 避免bug + // }); + // }); + // return Promise.reject(new Error('error')); + // } + // if (res.status === 40301) { + // Message({ + // message: '当前用户无相关操作权限!', + // type: 'error', + // duration: 5 * 1000 + // }); + // return Promise.reject(new Error('error')); + // } + // if (res.status === 40001) { + // Message({ + // message: '账户或密码错误!', + // type: 'warning' + // }); + // return Promise.reject(new Error('error')); + // } + // if (response.status !== 200 && res.status !== 200) { + // Message({ + // message: res.message, + // type: 'error', + // duration: 5 * 1000 + // }); + // } else { + // return response.data; + // } + }, + error => { + console.log(error); // for debug + // Message({ + // message: error.message, + // type: 'error', + // duration: 5 * 1000 + // }); + return Promise.reject(error); + } +); + +export default service; diff --git a/template/src/utils/validate.js b/template/src/utils/validate.js new file mode 100644 index 0000000000..99c6925d37 --- /dev/null +++ b/template/src/utils/validate.js @@ -0,0 +1,35 @@ +/* 是否是公司邮箱 */ +export function isWscnEmail (str) { + const reg = /^[a-z0-9](?:[-_.+]?[a-z0-9]+)*@wallstreetcn\.com$/i + return reg.test(str.trim()) +} + +/* 合法uri */ +export function validateURL (textval) { + const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ + return urlregex.test(textval) +} + +/* 小写字母 */ +export function validateLowerCase (str) { + const reg = /^[a-z]+$/ + return reg.test(str) +} + +/* 验证key */ +// export function validateKey(str) { +// var reg = /^[a-z_\-:]+$/; +// return reg.test(str); +// } + +/* 大写字母 */ +export function validateUpperCase (str) { + const reg = /^[A-Z]+$/ + return reg.test(str) +} + +/* 大小写字母 */ +export function validatAlphabets (str) { + const reg = /^[A-Za-z]+$/ + return reg.test(str) +} From 44c71a6cded20871fe172236910b1cd936bc2c61 Mon Sep 17 00:00:00 2001 From: guorongsen <49149153+guorongsen@users.noreply.github.com> Date: Thu, 20 Jun 2019 15:18:38 +0800 Subject: [PATCH 5/5] update update --- template/README.md | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/template/README.md b/template/README.md index df71d572cd..20fb821c01 100644 --- a/template/README.md +++ b/template/README.md @@ -1,9 +1,12 @@ -# {{ name }} +# githubtemp -> {{ description }} +默认使用vux,vuex,axios,vue-router + +封装axios请求,添加拦截,公共处理请求。 + +> A Vue.js project ## Build Setup -# guorongsen ``` bash # install dependencies @@ -17,21 +20,6 @@ npm run build # build for production and view the bundle analyzer report npm run build --report -{{#unit}} - -# run unit tests -npm run unit -{{/unit}} -{{#e2e}} - -# run e2e tests -npm run e2e -{{/e2e}} -{{#if_or unit e2e}} - -# run all tests -npm test -{{/if_or}} ``` For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).