Skip to content

Commit

Permalink
✨ 项目结构完善
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosen95 committed Sep 23, 2019
1 parent c602c22 commit cb9f192
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV=development
VUE_APP_API=
VUE_APP_DEV=true
3 changes: 3 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV=production
VUE_APP_API=
VUE_APP_DEV=false
3 changes: 3 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV=test
VUE_APP_API=
VUE_APP_DEV=false
11 changes: 10 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
module.exports = {
presets: ["@vue/app"]
presets: ["@vue/app"],
plugins: [
[
"component",
{
libraryName: "element-ui",
styleLibraryName: "theme-chalk"
}
]
]
};
117 changes: 112 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"axios": "^0.19.0",
"core-js": "^2.6.5",
"element-ui": "^2.12.0",
"vue": "^2.6.10",
"vue-class-component": "^7.0.2",
"vue-property-decorator": "^8.1.0",
Expand All @@ -28,6 +30,7 @@
"@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-prettier": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import store from "./store/index";

Vue.config.productionTip = false;

Expand Down
2 changes: 1 addition & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Vue.use(Router);

export default new Router({
mode: "history",
base: process.env.BASE_URL,
// base: process.env.BASE_URL,
routes: [
{
path: "/",
Expand Down
10 changes: 0 additions & 10 deletions src/store.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Vue from "vue";
import Vuex from "vuex";
import user from "./modules/user";

Vue.use(Vuex);

const store = new Vuex.Store({
strict: process.env.NODE_ENV !== "production",
modules: {
user
}
});

export default store;
8 changes: 8 additions & 0 deletions src/store/modules/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const user = {
state: {},
mutations: {},
actions: {},
getters: {}
};

export default user;
97 changes: 97 additions & 0 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import axios from "axios";

axios.defaults.headers = {
"Content-Type": "application/json;charset=utf8"
// token: Cookies.get("system_token") || ""
};

axios.defaults.baseURL = process.env.VUE_APP_API ? process.env.VUE_APP_API : "";
// console.log("process.env.VUE_APP_API", process.env.VUE_APP_API);

// 请求拦截器
axios.interceptors.request.use(
config => {
return config;
},
error => Promise.reject(error)
);

axios.interceptors.response.use(
response => {
return response;
},
error => Promise.resolve(error.response)
);

export function formateURLOnlyGet(link: string, json: object) {
let url = link;
var data = Object.entries(json);

if (data.length) {
url += url.indexOf("?") == -1 ? "?" : "";
url += Object.entries(data)
.map(item => {
return item[1].join("=");
})
.join("&");
}
return url;
}

/**
* GET请求方法
* @param {String} url 请求地址
* @param {json} json 请求参数
*/
export function getData(url: string, json: object) {
return axios
.get(formateURLOnlyGet(url, json))
.then(res => res.data)
.catch(error => error.response);
}

export function postData(url: string, json: object) {
return axios
.post(url, json)
.then(res => res.data)
.catch(error => error.response);
}
export function deleteData(url: string, json: object) {
return axios({
url: formateURLOnlyGet(url, json),
method: "delete"
// data: json
})
.then(res => res.data)
.catch(error => error.response);
}
export function deleteJSON(url: string, json: object) {
return axios({
url: url,
method: "delete",
data: json
})
.then(res => res.data)
.catch(error => error.response);
}
export function putData(url: string, json: object) {
return axios({
url,
method: "put",
data: json
})
.then(res => res.data)
.catch(error => error.response);
}

export function downloadFile(url: string, json: object) {
return axios({
url,
method: "post",
data: json,
withCredentials: true,
responseType: "blob"
})
.then(res => res)
.catch(error => error.response);
}
Loading

0 comments on commit cb9f192

Please sign in to comment.