Commit 53c98f6d by limin

1.3.9

1 parent 6574ea23
{ {
"printWidth": 800, "printWidth": 1800,
"tabWidth": 2, "tabWidth": 2,
"singleQuote": true, "singleQuote": true,
"trailingComma": "none", "trailingComma": "none",
"semi": false, "semi": false,
"wrap_line_length": 820, "wrap_line_length": 1820,
"wrap_attributes": "auto", "wrap_attributes": "auto",
"proseWrap": "always", "proseWrap": "always",
"arrowParens": "avoid", "arrowParens": "avoid",
......
...@@ -547,7 +547,7 @@ eval("\n\nvar GetIntrinsic = __webpack_require__(/*! get-intrinsic */ \"./node_m ...@@ -547,7 +547,7 @@ eval("\n\nvar GetIntrinsic = __webpack_require__(/*! get-intrinsic */ \"./node_m
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict"; "use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! qs */ \"./node_modules/qs/lib/index.js\");\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(qs__WEBPACK_IMPORTED_MODULE_2__);\n/*\r\n * @Author: limin\r\n * @Date: 2018-06-25 10:28:18\r\n * @Last Modified by: huyue\r\n * @Last Modified time: 2021-07-16 18:02:05\r\n */\r\n\r\n\r\n\r\nfunction Http(options = {}) {\r\n this.service = axios__WEBPACK_IMPORTED_MODULE_1___default().create({\r\n withCredentials: true,\r\n method: 'POST'\r\n })\r\n const {\r\n response = {},\r\n request: { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' },\r\n headers,\r\n alert,\r\n sign,\r\n signWay = 'sha1',\r\n secret\r\n } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay\r\n }\r\n Object.assign(this.service.defaults, { headers: Object.assign({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { baseURL, timeout, withCredentials, responseType })\r\n return this.create()\r\n}\r\nHttp.prototype.create = function () {\r\n this.service.interceptors.request.use(\r\n config => {\r\n let { data = {}, sign = true, noSignAttr = [] } = config\r\n if (sign) {\r\n let _configSign = this.customer.sign || {}\r\n data = (0,_util__WEBPACK_IMPORTED_MODULE_0__.createSign)(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLocaleLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\r\n }\r\n return config\r\n },\r\n error => Promise.reject(error)\r\n )\r\n this.service.interceptors.response.use(\r\n ({ data: res, config: { returnAll } }) => {\r\n const {\r\n response: { code_key = 'returnCode', errId = 'errId', code_success_value = '0', data_key = 'data' },\r\n alert\r\n } = this.customer\r\n let code = res[code_key]\r\n // let errId = res[errId]\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n // 请求成功,不弹提示框,成功code可以更改\r\n break\r\n default:\r\n alert && alert(res.message || res.msg || '出错了,请联系管理员')\r\n break\r\n }\r\n return returnAll ? res : res[data_key]\r\n },\r\n error => {\r\n const { alert } = this.customer\r\n alert && alert(error.message || '出错了,请联系管理员')\r\n // 返回接口返回的错误信息\r\n return Promise.reject(error)\r\n }\r\n )\r\n return this.service\r\n}\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Http);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/http.js?"); eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! qs */ \"./node_modules/qs/lib/index.js\");\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(qs__WEBPACK_IMPORTED_MODULE_2__);\n/*\r\n * @Author: limin\r\n * @Date: 2018-06-25 10:28:18\r\n * @Last Modified by: huyue\r\n * @Last Modified time: 2021-07-16 18:02:05\r\n */\r\n\r\n\r\n\r\nfunction Http(options = {}) {\r\n this.service = axios__WEBPACK_IMPORTED_MODULE_1___default().create({\r\n withCredentials: true,\r\n method: 'POST'\r\n })\r\n const { response = {}, request = {}, headers, alert, sign, signWay = 'sha1', secret } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay\r\n }\r\n const { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' } = request\r\n Object.assign(this.service.defaults, { headers: Object.assign({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { baseURL, timeout, withCredentials, responseType })\r\n return this.create()\r\n}\r\nHttp.prototype.create = function () {\r\n this.service.interceptors.request.use(\r\n config => {\r\n let { data = {}, sign = true, noSignAttr = [] } = config\r\n if (sign) {\r\n let _configSign = this.customer.sign || {}\r\n data = (0,_util__WEBPACK_IMPORTED_MODULE_0__.createSign)(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLocaleLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\r\n }\r\n return config\r\n },\r\n error => Promise.reject(error)\r\n )\r\n this.service.interceptors.response.use(\r\n ({ data: res, config: { returnAll } }) => {\r\n const {\r\n response: { code_key = 'returnCode', errId = 'errId', code_success_value = '0', data_key = 'data' },\r\n alert\r\n } = this.customer\r\n let code = res[code_key]\r\n // let errId = res[errId]\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n // 请求成功,不弹提示框,成功code可以更改\r\n break\r\n default:\r\n alert && alert(res.message || res.msg || '出错了,请联系管理员')\r\n break\r\n }\r\n return returnAll ? res : res[data_key]\r\n },\r\n error => {\r\n const { alert } = this.customer\r\n alert && alert(error.message || '出错了,请联系管理员')\r\n // 返回接口返回的错误信息\r\n return Promise.reject(error)\r\n }\r\n )\r\n this.service.axios = (axios__WEBPACK_IMPORTED_MODULE_1___default())\r\n return this.service\r\n}\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Http);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/http.js?");
/***/ }), /***/ }),
......
{ {
"name": "glsx-common", "name": "glsx-common",
"version": "1.3.8", "version": "1.3.9",
"description": "glsx common", "description": "glsx common",
"main": "./dist/glsx-common.js", "main": "./dist/glsx-common.js",
"private": false, "private": false,
......
...@@ -12,15 +12,7 @@ function Http(options = {}) { ...@@ -12,15 +12,7 @@ function Http(options = {}) {
withCredentials: true, withCredentials: true,
method: 'POST' method: 'POST'
}) })
const { const { response = {}, request = {}, headers, alert, sign, signWay = 'sha1', secret } = options
response = {},
request: { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' },
headers,
alert,
sign,
signWay = 'sha1',
secret
} = options
this.customer = { this.customer = {
response, response,
alert, alert,
...@@ -28,6 +20,7 @@ function Http(options = {}) { ...@@ -28,6 +20,7 @@ function Http(options = {}) {
secret, secret,
signWay signWay
} }
const { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' } = request
Object.assign(this.service.defaults, { headers: Object.assign({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { baseURL, timeout, withCredentials, responseType }) Object.assign(this.service.defaults, { headers: Object.assign({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { baseURL, timeout, withCredentials, responseType })
return this.create() return this.create()
} }
...@@ -75,6 +68,7 @@ Http.prototype.create = function () { ...@@ -75,6 +68,7 @@ Http.prototype.create = function () {
return Promise.reject(error) return Promise.reject(error)
} }
) )
this.service.axios = axios
return this.service return this.service
} }
export default Http export default Http
import "./iconfont/iconfont.css";
import "./style/index.scss";
const _import = require("./import/import-" + process.env.NODE_ENV);
// 为vuex添加global模块,存储全局下发的数据
function registerGlobalModule(store, props = {}) {
if (!store || !store.hasModule) return;
// 初始化数据
const initState = { ...props.globalState };
if (!store.hasModule("global")) {
const globalModule = {
namespaced: true,
state: initState,
actions: {
// 子应用改变state并通知父应用
setGlobalState({ commit }, payload) {
commit("setGlobalState", payload);
commit("emitGlobalState", payload);
},
// 初始化,只用于mount时同步父应用的数据
initGlobalState({ commit }, payload) {
commit("setGlobalState", payload);
},
},
mutations: {
setGlobalState(state, payload) {
state = Object.assign(state, payload);
},
emitGlobalState(state) {
if (props.setGlobalState) {
props.setGlobalState(state);
}
},
},
};
store.registerModule("global", globalModule);
} else {
// 每次mount时,都同步一次父应用数据
store.dispatch("global/initGlobalState", initState);
}
}
// 为vuex添加routes模块,存储及修改动态路由数据
function registerRoutesModule(store) {
if (!store || !store.hasModule) return;
if (!store.hasModule("routes")) {
const routesModule = {
namespaced: true,
state: {
routesData: [],
},
mutations: {
UPDATE_ROUTER_DATA(state, payload) {
state.routesData = payload;
},
},
};
store.registerModule("routes", routesModule);
}
}
// 封装路由数据
function getRoutes({ name, id, routesData }) {
const routes = [];
if (routesData && name && id) {
for (let i = 0, length = routesData.length; i < length; i += 1) {
const element = routesData[i];
if (element.path && element.path.includes(name) && element.meta && element.meta.id && element.meta.id.startsWith(id)) {
const path = element.path.slice(name.length + 1);
element.path = path;
element.component = _import(path);
routes.push(element);
}
}
}
return routes;
}
function initGlobalState(store, props) {
registerGlobalModule(store, props);
// registerRoutesModule(store);
// const routes = getRoutes(store, props);
// return routes;
}
export default {
initGlobalState,
getRoutes,
};
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!