Skip to content

Commit

Permalink
(feature)准备添加环境变量相关
Browse files Browse the repository at this point in the history
  • Loading branch information
jingchenxu committed Jul 29, 2019
1 parent 5c1bfd7 commit eacc03f
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASE_URL = '/myview'
VUE_APP = 'MYVIEW_ADMIN'
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "yarn run serve -o",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
Expand All @@ -28,7 +29,6 @@
"vuex": "^3.0.1"
},
"devDependencies": {
"babel-plugin-component": "^1.1.1",
"@types/chai": "^4.1.0",
"@types/mocha": "^5.2.4",
"@vue/cli-plugin-babel": "^3.9.0",
Expand All @@ -42,11 +42,14 @@
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/test-utils": "1.0.0-beta.29",
"babel-eslint": "^10.0.1",
"babel-plugin-component": "^1.1.1",
"chai": "^4.1.2",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"mock": "^0.1.1",
"mockjs": "^1.0.1-beta3",
"typescript": "^3.4.3",
"vue-template-compiler": "^2.6.10"
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import './registerServiceWorker'
import iView from 'iview'
import { Aside, Main, Header, Container, RadioButton, RadioGroup, Submenu, MenuItemGroup, MenuItem, Menu } from 'element-ui'
import myView from './myview'
import './mock'
import vueplugin from './utils/vueplugin'

Vue.config.productionTip = false

Vue.use(iView)
Vue.use(myView)
Vue.use(vueplugin)

Vue.component('el-aside', Aside)
Vue.component('el-main', Main)
Expand Down
3 changes: 3 additions & 0 deletions src/mock/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Mock from './mock'

export default Mock
22 changes: 22 additions & 0 deletions src/mock/mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SysMenu from './types/SysMenu'
const Mock = require('mockjs')

Mock.mock('/api/data', 'get', (req, res) => {
let sysMenu = new SysMenu()
sysMenu.mid = '1213'
return {
success: true,
data: sysMenu,
msg: 'success'
}
})

Mock.mock('/api/login', 'post', (req, res) => {
return {
success: true,
data: {},
msg: '登录成功'
}
})

export default Mock
17 changes: 17 additions & 0 deletions src/mock/types/SysMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default class {

constructor () {
this.mid = ''
this.mkey = ''
this.mname = ''
}

private mid: String
private mkey: String
private mname: String

setMid(mid:String): void {
this.mid = mid
}

}
36 changes: 36 additions & 0 deletions src/mock/types/sys/SysUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export default class {

constructor () {
this.userid = ''
this.username = ''
this.usersex = ''
this.birthday = ''
this.password = ''
this.nickname = ''
this.email = ''
this.createdate = ''
this.modifydate = ''
this.isadmin = ''
this.age = ''
this.loginip = ''
this.userstatus = ''
this.error = ''
this.islock = ''
}
private userid:String
private username:String
private usersex:String
private birthday:String
private password:String
private nickname:String
private email:String
private createdate:String
private modifydate:String
private isadmin:String
private age:String
private loginip:String
private userstatus:String
private error:String
private islock:String

}
2 changes: 1 addition & 1 deletion src/myview/CopyRight/CopyRight.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="copy-right">

<h1>Copy Right</h1>
</div>
</template>

Expand Down
36 changes: 36 additions & 0 deletions src/types/sys/SysUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export default class {

constructor () {
this.userid = ''
this.username = ''
this.usersex = ''
this.birthday = ''
this.password = ''
this.nickname = ''
this.email = ''
this.createdate = ''
this.modifydate = ''
this.isadmin = ''
this.age = ''
this.loginip = ''
this.userstatus = ''
this.error = ''
this.islock = ''
}
private userid:String
private username:String
private usersex:String
private birthday:String
private password:String
private nickname:String
private email:String
private createdate:String
private modifydate:String
private isadmin:String
private age:String
private loginip:String
private userstatus:String
private error:String
private islock:String

}
3 changes: 3 additions & 0 deletions src/utils/vueplugin/bus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Vue from 'vue'

export default new Vue()
3 changes: 3 additions & 0 deletions src/utils/vueplugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import vueplugin from './vueplugin'

export default vueplugin
25 changes: 25 additions & 0 deletions src/utils/vueplugin/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import axios from 'axios'

const request = function (option = {}) {
const _request = axios.create({
withCredentials: true,
charset: 'UTF_8',
timeout: 300000,
baseURL: process.env.BASE_URL
})

// 以下是响应拦截器
_request.interceptors.response.use(res => {
console.log('拦截到请求响应')
return res.data
})

// 以下是请求拦截器
_request.interceptors.request.use(req => {
return req
})

return _request
}

export default request
11 changes: 11 additions & 0 deletions src/utils/vueplugin/vueplugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import request from './request'
import bus from './bus'

let vueplugin = {}

vueplugin.install = function (Vue, options) {
Vue.prototype.$axios = request()
Vue.prototype.$bus = bus
}

export default vueplugin
30 changes: 22 additions & 8 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
<template>
<div class="login-container">
<Form class="login-form" ref="formInline" :model="formInline" :rules="ruleInline">
<Form class="login-form" ref="login" :model="form" :rules="rule">
<div class="logo-container">

</div>
<FormItem prop="user">
<Input size="large" type="text" v-model="formInline.user" placeholder="Username">
<Input size="large" type="text" v-model="form.user" placeholder="Username">
<Icon type="ios-person-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem prop="password">
<Input size="large" type="password" v-model="formInline.password" placeholder="Password">
<Input size="large" type="password" v-model="form.password" placeholder="Password">
<Icon type="ios-lock-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem prop="rememberPassword">
<Checkbox v-model="formInline.rememberPassword">记住密码</Checkbox>
<Checkbox v-model="form.rememberPassword">记住密码</Checkbox>
</FormItem>
<FormItem>
<Button size="large" long type="primary" @click="handleSubmit('formInline')">登录</Button>
<Button size="large" long type="primary" @click="handleLogin('login')">登录</Button>
</FormItem>
</Form>
</div>
</template>

<script>
import axios from 'axios'
export default {
name: 'Login',
data () {
return {
formInline: {},
ruleInline: {}
form: {
rememberPassword: false
},
rule: {}
}
},
methods: {
handleSubmit () {
handleLogin () {
console.dir(process.env)
this.$axios.post('/api/login', this.form).then(res => {
console.dir(res)
if (res.success) {
this.$Message.success(res.msg)
this.linkToMis()
}
})
},
linkToMis () {
this.$router.push({
name: 'index'
})
Expand Down
12 changes: 10 additions & 2 deletions src/views/mis/sys/SysPage1.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<template>
<div>
<h1>SysPage1</h1>
<h1>SysPage1__</h1>
</div>
</template>

<script>
import axios from 'axios'
export default {
name: 'SysPage1'
name: 'SysPage1',
mounted () {
console.log('请求开始')
axios.get('/api/data').then( res => {
console.dir(res)
})
}
}
</script>
22 changes: 17 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

commander@*, commander@^2.12.1, commander@^2.18.0, commander@^2.20.0:
version "2.20.0"
resolved "https://registry.npm.taobao.org/commander/download/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha1-1YuytcHuj4ew00ACfp6U4iLFpCI=

commander@2.15.1:
version "2.15.1"
resolved "https://registry.npm.taobao.org/commander/download/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
Expand All @@ -2538,11 +2543,6 @@ commander@2.17.x:
resolved "https://registry.npm.taobao.org/commander/download/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
integrity sha1-vXerfebelCBc6sxy8XFtKfIKd78=

commander@^2.12.1, commander@^2.18.0, commander@^2.20.0:
version "2.20.0"
resolved "https://registry.npm.taobao.org/commander/download/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha1-1YuytcHuj4ew00ACfp6U4iLFpCI=

commander@~2.19.0:
version "2.19.0"
resolved "https://registry.npm.taobao.org/commander/download/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
Expand Down Expand Up @@ -6301,6 +6301,18 @@ mocha@^5.2.0:
mkdirp "0.5.1"
supports-color "5.4.0"

mock@^0.1.1:
version "0.1.1"
resolved "https://registry.npm.taobao.org/mock/download/mock-0.1.1.tgz#e7e3589c7e6b3376d69f5a3e470b56604417c633"
integrity sha1-5+NYnH5rM3bWn1o+RwtWYEQXxjM=

mockjs@^1.0.1-beta3:
version "1.0.1-beta3"
resolved "https://registry.npm.taobao.org/mockjs/download/mockjs-1.0.1-beta3.tgz#d234f3c27256397564f2c955142e891909537209"
integrity sha1-0jTzwnJWOXVk8slVFC6JGQlTcgk=
dependencies:
commander "*"

moment@2.24.0, moment@^2.24.0:
version "2.24.0"
resolved "https://registry.npm.taobao.org/moment/download/moment-2.24.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmoment%2Fdownload%2Fmoment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
Expand Down

0 comments on commit eacc03f

Please sign in to comment.