diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b163ca8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/unpackage diff --git a/common/api.js b/common/api.js index 56d5049..43ba72b 100644 --- a/common/api.js +++ b/common/api.js @@ -9,4 +9,40 @@ export const fetchMenu = (params, config = {}) => http.post('/ebapi/public_api/i * 登录的接口 */ // 微信登录接口 -export const wxLogin = (params) => http.get('/api/login/login', {params:params}) \ No newline at end of file +export const appletLogin = (params) => http.get('/employ-api/user/login', {params:params}) +// 招聘方填写信息 +export const roleBoss = (params) => http.post('/employ-api/user/roleBoss', params) +// 求职者填写信息 +export const role = (params) => http.post('/employ-api/user/role', params) + + +// 首页行业菜单 +export const industryList = (params) => http.get('/employ-api/index/industryList', {params:params}) +// 获取banner列表 +export const bannerList = (params) => http.post('/employ-api/index/bannerList', params) +// 招聘大厅列表查询 +export const taskList = (params) => http.get('/employ-api/index/taskList', {params:params}) +// 求职大厅列表查询 +export const rolelist = (params) => http.get('/employ-api/index/rolelist1', {params:params}) +// 公司发布任务 +export const addTask = (params) => http.post('/employ-api/user/addTask', params) +// 根据行业id查询工种 +export const industryById = (params) => http.get('/employ-api/index/getIndustryById', {params:params}) +// tb_user_role-通过id查询 +export const getTaskById = (params) => http.get('/employ-api/user/getTaskById', {params:params}) + +// 我的头像昵称,平台客户电话等信息 +export const userInfo = (params) => http.post('/employ-api/index/index', params) +// 帮助与反馈 +export const addSuggest = (params) => http.post('/employ-api/index/addSuggest', params) +// 余额日志 +export const payLog = (params) => http.post('/employ-api/pay/log', params) +// 充值支付 +export const payRecharge = (params) => http.post('/employ-api/pay/payRecharge', params) +// 提现 +export const withdrawal = (params) => http.post('/employ-api/pay/withdrawal', params) + +// 招聘方订单分页列表查询 +export const bossOrderList = (params) => http.post('/employ-api/order/bossOrderList', params) +// 发起聘请,等待师傅确认 +export const orderTask = (params) => http.post('/employ-api/order/addTask', params) diff --git a/common/config.js b/common/config.js index 3c9ffd6..5db0976 100644 --- a/common/config.js +++ b/common/config.js @@ -1,5 +1,6 @@ module.exports = { - baseUrl: 'https://employadmin.augcl.com/employ-api', - // baseUrl: 'http://augcl.natapp1.cc/employ-api' + // baseUrl: 'https://employadmin.augcl.com/employ-api', + // baseUrl: 'http://3fl8266127.qicp.vip/' + baseUrl:"https://employadmin.hhlm1688.com" } diff --git a/main.js b/main.js index e94cdaf..8874db1 100644 --- a/main.js +++ b/main.js @@ -11,6 +11,7 @@ import mixin from './common/mixin' Vue.prototype.$store = store + Vue.config.productionTip = false App.mpType = 'app' @@ -36,4 +37,5 @@ const app = new Vue({ // 引入请求封装 require('./util/request/index')(app) + app.$mount() diff --git a/manifest.json b/manifest.json index 880cea6..ae55e7f 100644 --- a/manifest.json +++ b/manifest.json @@ -96,7 +96,13 @@ }, "quickapp" : {}, "mp-weixin" : { - "appid" : "wx81ac70f6f1ae8854", + "appid" : "wx6931d85f7371b032", + "permission" : { + "scope.userLocation" : { + "desc" : "将获取你的具体位置信息,用于帮助用户浏览所在位置的" + } + }, + "requiredPrivateInfos" : [ "getLocation", "chooseLocation" ], "setting" : { "urlCheck" : false, "es6" : false, diff --git a/pages.json b/pages.json index c0dd0f6..880e545 100644 --- a/pages.json +++ b/pages.json @@ -1,34 +1,34 @@ { "pages": [ { - "path": "pages/user/index", + "path": "pages/home/index", "style": { - "navigationBarTitleText": "我的", + "navigationBarTitleText": "首页", "navigationStyle":"default", "navigationBarBackgroundColor": "#FF7A31", - "navigationBarTextStyle": "white" + "navigationBarTextStyle": "white", + "enablePullDownRefresh": true, + "onReachBottomDistance": 100 } }, { - "path": "pages/order/index", + "path": "pages/user/index", "style": { - "navigationBarTitleText": "订单", + "navigationBarTitleText": "我的", "navigationStyle":"default", "navigationBarBackgroundColor": "#FF7A31", "navigationBarTextStyle": "white" } }, { - "path": "pages/home/index", + "path": "pages/order/index", "style": { - "navigationBarTitleText": "首页", + "navigationBarTitleText": "订单", "navigationStyle":"default", "navigationBarBackgroundColor": "#FF7A31", "navigationBarTextStyle": "white" } }, - - { "path": "pages/identity/index", "style": { @@ -197,9 +197,7 @@ ] } ], - "preloadRule": { - - }, + "globalStyle": { "navigationBarBackgroundColor": "#ffffff", "backgroundColor": "#f5f5f5", diff --git a/pages/auth/index.vue b/pages/auth/index.vue index 9a98443..b138512 100644 --- a/pages/auth/index.vue +++ b/pages/auth/index.vue @@ -9,10 +9,10 @@ - + @@ -54,7 +54,7 @@ diff --git a/pages/user/index.vue b/pages/user/index.vue index 1ee93d1..fb540e7 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -2,10 +2,10 @@ - + - 热心小肖 + {{nickName}} 修改资料 @@ -13,7 +13,7 @@ 手机号: - 13189698114 + {{phone}} @@ -31,7 +31,7 @@ 我的余额 - ¥1200 + ¥{{myMoney}} @@ -51,9 +51,10 @@ - + + - + @@ -91,18 +92,50 @@ diff --git a/pages_subpack/release/component/master.vue b/pages_subpack/release/component/master.vue index 399e726..f4bcb0b 100644 --- a/pages_subpack/release/component/master.vue +++ b/pages_subpack/release/component/master.vue @@ -3,29 +3,28 @@ - - - + + + + - + - + + + + + - + @@ -77,47 +76,30 @@ - + - + - - - - diff --git a/pages_subpack/wallet/component/recharge.vue b/pages_subpack/wallet/component/recharge.vue index f051deb..e0f7b81 100644 --- a/pages_subpack/wallet/component/recharge.vue +++ b/pages_subpack/wallet/component/recharge.vue @@ -26,15 +26,31 @@ \ No newline at end of file diff --git a/static/common/js/touch-emulator.js b/static/common/js/touch-emulator.js deleted file mode 100644 index b90c8ac..0000000 --- a/static/common/js/touch-emulator.js +++ /dev/null @@ -1,363 +0,0 @@ -(function (window, document, exportName, undefined) { - "use strict"; - - var isMultiTouch = false; - var multiTouchStartPos; - var eventTarget; - var touchElements = {}; - - // polyfills - if (!document.createTouch) { - document.createTouch = function (view, target, identifier, pageX, pageY, screenX, screenY, clientX, clientY) { - // auto set - if (clientX == undefined || clientY == undefined) { - clientX = pageX - window.pageXOffset; - clientY = pageY - window.pageYOffset; - } - - return new Touch(target, identifier, { - pageX: pageX, - pageY: pageY, - screenX: screenX, - screenY: screenY, - clientX: clientX, - clientY: clientY - }); - }; - } - - if (!document.createTouchList) { - document.createTouchList = function () { - var touchList = new TouchList(); - for (var i = 0; i < arguments.length; i++) { - touchList[i] = arguments[i]; - } - touchList.length = arguments.length; - return touchList; - }; - } - - /** - * create an touch point - * @constructor - * @param target - * @param identifier - * @param pos - * @param deltaX - * @param deltaY - * @returns {Object} touchPoint - */ - function Touch(target, identifier, pos, deltaX, deltaY) { - deltaX = deltaX || 0; - deltaY = deltaY || 0; - - this.identifier = identifier; - this.target = target; - this.clientX = pos.clientX + deltaX; - this.clientY = pos.clientY + deltaY; - this.screenX = pos.screenX + deltaX; - this.screenY = pos.screenY + deltaY; - this.pageX = pos.pageX + deltaX; - this.pageY = pos.pageY + deltaY; - } - - /** - * create empty touchlist with the methods - * @constructor - * @returns touchList - */ - function TouchList() { - var touchList = []; - - touchList.item = function (index) { - return this[index] || null; - }; - - // specified by Mozilla - touchList.identifiedTouch = function (id) { - return this[id + 1] || null; - }; - - return touchList; - } - - - /** - * Simple trick to fake touch event support - * this is enough for most libraries like Modernizr and Hammer - */ - function fakeTouchSupport() { - var objs = [window, document.documentElement]; - var props = ['ontouchstart', 'ontouchmove', 'ontouchcancel', 'ontouchend']; - - for (var o = 0; o < objs.length; o++) { - for (var p = 0; p < props.length; p++) { - if (objs[o] && objs[o][props[p]] == undefined) { - objs[o][props[p]] = null; - } - } - } - } - - /** - * we don't have to emulate on a touch device - * @returns {boolean} - */ - function hasTouchSupport() { - return ("ontouchstart" in window) || // touch events - (window.Modernizr && window.Modernizr.touch) || // modernizr - (navigator.msMaxTouchPoints || navigator.maxTouchPoints) > 2; // pointer events - } - - /** - * disable mouseevents on the page - * @param ev - */ - function preventMouseEvents(ev) { - // 注释启用默认事件 - // ev.preventDefault(); - // ev.stopPropagation(); - } - - /** - * only trigger touches when the left mousebutton has been pressed - * @param touchType - * @returns {Function} - */ - function onMouse(touchType) { - return function (ev) { - // prevent mouse events - preventMouseEvents(ev); - - if (ev.which !== 1) { - return; - } - - // The EventTarget on which the touch point started when it was first placed on the surface, - // even if the touch point has since moved outside the interactive area of that element. - // also, when the target doesnt exist anymore, we update it - if (ev.type == 'mousedown' || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)) { - eventTarget = ev.target; - } - - // shiftKey has been lost, so trigger a touchend - if (isMultiTouch && !ev.shiftKey) { - triggerTouch('touchend', ev); - isMultiTouch = false; - } - - triggerTouch(touchType, ev); - - // we're entering the multi-touch mode! - if (!isMultiTouch && ev.shiftKey) { - isMultiTouch = true; - multiTouchStartPos = { - pageX: ev.pageX, - pageY: ev.pageY, - clientX: ev.clientX, - clientY: ev.clientY, - screenX: ev.screenX, - screenY: ev.screenY - }; - triggerTouch('touchstart', ev); - } - - // reset - if (ev.type == 'mouseup') { - multiTouchStartPos = null; - isMultiTouch = false; - eventTarget = null; - } - } - } - - /** - * trigger a touch event - * @param eventName - * @param mouseEv - */ - function triggerTouch(eventName, mouseEv) { - var touchEvent = document.createEvent('Event'); - touchEvent.initEvent(eventName, true, true); - - touchEvent.altKey = mouseEv.altKey; - touchEvent.ctrlKey = mouseEv.ctrlKey; - touchEvent.metaKey = mouseEv.metaKey; - touchEvent.shiftKey = mouseEv.shiftKey; - - touchEvent.touches = getActiveTouches(mouseEv, eventName); - touchEvent.targetTouches = getActiveTouches(mouseEv, eventName); - touchEvent.changedTouches = getChangedTouches(mouseEv, eventName); - - eventTarget.dispatchEvent(touchEvent); - } - - /** - * create a touchList based on the mouse event - * @param mouseEv - * @returns {TouchList} - */ - function createTouchList(mouseEv) { - var touchList = new TouchList(); - - if (isMultiTouch) { - var f = TouchEmulator.multiTouchOffset; - var deltaX = multiTouchStartPos.pageX - mouseEv.pageX; - var deltaY = multiTouchStartPos.pageY - mouseEv.pageY; - - touchList.push(new Touch(eventTarget, 1, multiTouchStartPos, (deltaX * -1) - f, (deltaY * -1) + f)); - touchList.push(new Touch(eventTarget, 2, multiTouchStartPos, deltaX + f, deltaY - f)); - } else { - touchList.push(new Touch(eventTarget, 1, mouseEv, 0, 0)); - } - - return touchList; - } - - /** - * receive all active touches - * @param mouseEv - * @returns {TouchList} - */ - function getActiveTouches(mouseEv, eventName) { - // empty list - if (mouseEv.type == 'mouseup') { - return new TouchList(); - } - - var touchList = createTouchList(mouseEv); - if (isMultiTouch && mouseEv.type != 'mouseup' && eventName == 'touchend') { - touchList.splice(1, 1); - } - return touchList; - } - - /** - * receive a filtered set of touches with only the changed pointers - * @param mouseEv - * @param eventName - * @returns {TouchList} - */ - function getChangedTouches(mouseEv, eventName) { - var touchList = createTouchList(mouseEv); - - // we only want to return the added/removed item on multitouch - // which is the second pointer, so remove the first pointer from the touchList - // - // but when the mouseEv.type is mouseup, we want to send all touches because then - // no new input will be possible - if (isMultiTouch && mouseEv.type != 'mouseup' && - (eventName == 'touchstart' || eventName == 'touchend')) { - touchList.splice(0, 1); - } - - return touchList; - } - - /** - * show the touchpoints on the screen - */ - function showTouches(ev) { - var touch, i, el, styles; - - // first all visible touches - for (i = 0; i < ev.touches.length; i++) { - touch = ev.touches[i]; - el = touchElements[touch.identifier]; - if (!el) { - el = touchElements[touch.identifier] = document.createElement("div"); - document.body.appendChild(el); - } - - styles = TouchEmulator.template(touch); - for (var prop in styles) { - el.style[prop] = styles[prop]; - } - } - - // remove all ended touches - if (ev.type == 'touchend' || ev.type == 'touchcancel') { - for (i = 0; i < ev.changedTouches.length; i++) { - touch = ev.changedTouches[i]; - el = touchElements[touch.identifier]; - if (el) { - el.parentNode.removeChild(el); - delete touchElements[touch.identifier]; - } - } - } - } - - /** - * TouchEmulator initializer - */ - function TouchEmulator() { - if (hasTouchSupport()) { - return; - } - - fakeTouchSupport(); - - window.addEventListener("mousedown", onMouse('touchstart'), true); - window.addEventListener("mousemove", onMouse('touchmove'), true); - window.addEventListener("mouseup", onMouse('touchend'), true); - - window.addEventListener("mouseenter", preventMouseEvents, true); - window.addEventListener("mouseleave", preventMouseEvents, true); - window.addEventListener("mouseout", preventMouseEvents, true); - window.addEventListener("mouseover", preventMouseEvents, true); - - // it uses itself! - window.addEventListener("touchstart", showTouches, true); - window.addEventListener("touchmove", showTouches, true); - window.addEventListener("touchend", showTouches, true); - window.addEventListener("touchcancel", showTouches, true); - } - - // start distance when entering the multitouch mode - TouchEmulator.multiTouchOffset = 75; - - /** - * css template for the touch rendering - * @param touch - * @returns object - */ - TouchEmulator.template = function (touch) { - var size = 0; - var transform = 'translate(' + (touch.clientX - (size / 2)) + 'px, ' + (touch.clientY - (size / 2)) + 'px)'; - return { - position: 'fixed', - left: 0, - top: 0, - background: '#fff', - border: 'solid 1px #999', - opacity: .6, - borderRadius: '100%', - height: size + 'px', - width: size + 'px', - padding: 0, - margin: 0, - display: 'block', - overflow: 'hidden', - pointerEvents: 'none', - webkitUserSelect: 'none', - mozUserSelect: 'none', - userSelect: 'none', - webkitTransform: transform, - mozTransform: transform, - transform: transform, - zIndex: 100 - } - }; - - // export - if (typeof define == "function" && define.amd) { - define(function () { - return TouchEmulator; - }); - } else if (typeof module != "undefined" && module.exports) { - module.exports = TouchEmulator; - } else { - window[exportName] = TouchEmulator; - } -})(window, document, "TouchEmulator"); \ No newline at end of file diff --git a/static/image/46502.png b/static/image/46502.png index d8bc6f4..1660a4c 100644 Binary files a/static/image/46502.png and b/static/image/46502.png differ diff --git a/static/image/46518.png b/static/image/46518.png index 3f79f7a..e5059c3 100644 Binary files a/static/image/46518.png and b/static/image/46518.png differ diff --git a/static/image/46524.png b/static/image/46524.png index 535b3b6..0e684cb 100644 Binary files a/static/image/46524.png and b/static/image/46524.png differ diff --git a/static/image/46525.png b/static/image/46525.png index 4e1d7f1..a1c0689 100644 Binary files a/static/image/46525.png and b/static/image/46525.png differ diff --git a/static/image/46662.png b/static/image/46662.png index 4c37d8e..8dbe048 100644 Binary files a/static/image/46662.png and b/static/image/46662.png differ diff --git a/static/image/47761.png b/static/image/47761.png index b84b91b..3a98d0f 100644 Binary files a/static/image/47761.png and b/static/image/47761.png differ diff --git a/static/image/4777.png b/static/image/4777.png deleted file mode 100644 index bf48c3a..0000000 Binary files a/static/image/4777.png and /dev/null differ diff --git a/static/image/47822.png b/static/image/47822.png index 1db6bf3..c663c2c 100644 Binary files a/static/image/47822.png and b/static/image/47822.png differ diff --git a/static/image/47961.png b/static/image/47961.png index 2bf3a8c..1cbe5a9 100644 Binary files a/static/image/47961.png and b/static/image/47961.png differ diff --git a/static/image/59.png b/static/image/59.png index c8e8c5e..440e0c7 100644 Binary files a/static/image/59.png and b/static/image/59.png differ diff --git a/static/image/6584.png b/static/image/6584.png index ca6d6b5..7336f67 100644 Binary files a/static/image/6584.png and b/static/image/6584.png differ diff --git a/static/image/6588.png b/static/image/6588.png index c93a2c6..452681d 100644 Binary files a/static/image/6588.png and b/static/image/6588.png differ diff --git a/static/image/7822.png b/static/image/7822.png index 4a2a1b1..91d441c 100644 Binary files a/static/image/7822.png and b/static/image/7822.png differ diff --git a/static/image/aed60x.png b/static/image/aed60x.png index 6fc2912..ec0d160 100644 Binary files a/static/image/aed60x.png and b/static/image/aed60x.png differ diff --git a/static/image/banner.png b/static/image/banner.png deleted file mode 100644 index a38907f..0000000 Binary files a/static/image/banner.png and /dev/null differ diff --git a/static/image/header.png b/static/image/header.png index d6625c7..236afb6 100644 Binary files a/static/image/header.png and b/static/image/header.png differ diff --git a/static/image/home.png b/static/image/home.png index 34bfbf9..50cbd23 100644 Binary files a/static/image/home.png and b/static/image/home.png differ diff --git a/static/image/home_selected.png b/static/image/home_selected.png index c1ac305..829833c 100644 Binary files a/static/image/home_selected.png and b/static/image/home_selected.png differ diff --git a/static/image/logo.png b/static/image/logo.png index 962b34b..4274b15 100644 Binary files a/static/image/logo.png and b/static/image/logo.png differ diff --git a/static/image/nav1.png b/static/image/nav1.png index 3821260..ab28077 100644 Binary files a/static/image/nav1.png and b/static/image/nav1.png differ diff --git a/static/image/nav2.png b/static/image/nav2.png index c37ec87..30a812a 100644 Binary files a/static/image/nav2.png and b/static/image/nav2.png differ diff --git a/static/image/nav3.png b/static/image/nav3.png index dde11ef..f045eae 100644 Binary files a/static/image/nav3.png and b/static/image/nav3.png differ diff --git a/static/image/nav4.png b/static/image/nav4.png index ee1e4e3..22383c0 100644 Binary files a/static/image/nav4.png and b/static/image/nav4.png differ diff --git a/static/image/nav5.png b/static/image/nav5.png index f65b508..fd3e5a9 100644 Binary files a/static/image/nav5.png and b/static/image/nav5.png differ diff --git a/static/image/nav6.png b/static/image/nav6.png index 9a7d2b7..be548d1 100644 Binary files a/static/image/nav6.png and b/static/image/nav6.png differ diff --git a/static/image/nav7.png b/static/image/nav7.png index d9c175f..cc7a1c9 100644 Binary files a/static/image/nav7.png and b/static/image/nav7.png differ diff --git a/static/image/nav8.png b/static/image/nav8.png index 17024cd..b6169a8 100644 Binary files a/static/image/nav8.png and b/static/image/nav8.png differ diff --git a/static/image/order.png b/static/image/order.png index c134445..7557d7b 100644 Binary files a/static/image/order.png and b/static/image/order.png differ diff --git a/static/image/order_selected.png b/static/image/order_selected.png index d935abf..a6123d0 100644 Binary files a/static/image/order_selected.png and b/static/image/order_selected.png differ diff --git a/static/image/pencil.png b/static/image/pencil.png index d631a20..3524043 100644 Binary files a/static/image/pencil.png and b/static/image/pencil.png differ diff --git a/static/image/piao.png b/static/image/piao.png index 75ef6dd..879eb6b 100644 Binary files a/static/image/piao.png and b/static/image/piao.png differ diff --git a/static/image/release_btn.png b/static/image/release_btn.png index 783e722..bf5c76d 100644 Binary files a/static/image/release_btn.png and b/static/image/release_btn.png differ diff --git a/static/image/setting.png b/static/image/setting.png index 6989c9d..65cdcc6 100644 Binary files a/static/image/setting.png and b/static/image/setting.png differ diff --git a/static/image/success.png b/static/image/success.png index a9ddd41..c57cc52 100644 Binary files a/static/image/success.png and b/static/image/success.png differ diff --git a/static/image/user.png b/static/image/user.png index 69dc7a7..b28bcea 100644 Binary files a/static/image/user.png and b/static/image/user.png differ diff --git a/static/image/user_selected.png b/static/image/user_selected.png index 965d6bf..b32cbbf 100644 Binary files a/static/image/user_selected.png and b/static/image/user_selected.png differ diff --git a/static/image/wall.png b/static/image/wall.png index c066ebd..7e78682 100644 Binary files a/static/image/wall.png and b/static/image/wall.png differ diff --git a/static/image/wechat.png b/static/image/wechat.png index 948dd74..980d425 100644 Binary files a/static/image/wechat.png and b/static/image/wechat.png differ diff --git a/static/uview/common/favicon.ico b/static/uview/common/favicon.ico deleted file mode 100644 index e0af368..0000000 Binary files a/static/uview/common/favicon.ico and /dev/null differ diff --git a/static/uview/common/gray-logo.png b/static/uview/common/gray-logo.png deleted file mode 100644 index 21a6994..0000000 Binary files a/static/uview/common/gray-logo.png and /dev/null differ diff --git a/static/uview/common/logo.png b/static/uview/common/logo.png deleted file mode 100644 index 05b3aed..0000000 Binary files a/static/uview/common/logo.png and /dev/null differ diff --git a/static/uview/example/component.png b/static/uview/example/component.png deleted file mode 100644 index 9464b23..0000000 Binary files a/static/uview/example/component.png and /dev/null differ diff --git a/static/uview/example/component_select.png b/static/uview/example/component_select.png deleted file mode 100644 index 79efb5b..0000000 Binary files a/static/uview/example/component_select.png and /dev/null differ diff --git a/static/uview/example/js.png b/static/uview/example/js.png deleted file mode 100644 index beb0dc7..0000000 Binary files a/static/uview/example/js.png and /dev/null differ diff --git a/static/uview/example/js_bak.png b/static/uview/example/js_bak.png deleted file mode 100644 index d280e3d..0000000 Binary files a/static/uview/example/js_bak.png and /dev/null differ diff --git a/static/uview/example/js_select.png b/static/uview/example/js_select.png deleted file mode 100644 index e8309a4..0000000 Binary files a/static/uview/example/js_select.png and /dev/null differ diff --git a/static/uview/example/template.png b/static/uview/example/template.png deleted file mode 100644 index ff895b8..0000000 Binary files a/static/uview/example/template.png and /dev/null differ diff --git a/static/uview/example/template_select.png b/static/uview/example/template_select.png deleted file mode 100644 index 90d6601..0000000 Binary files a/static/uview/example/template_select.png and /dev/null differ diff --git a/util/qqmap-wx-jssdk.min.js b/util/qqmap-wx-jssdk.min.js new file mode 100644 index 0000000..8fa1477 --- /dev/null +++ b/util/qqmap-wx-jssdk.min.js @@ -0,0 +1 @@ +var ERROR_CONF = { KEY_ERR: 311, KEY_ERR_MSG: 'key格式错误', PARAM_ERR: 310, PARAM_ERR_MSG: '请求参数信息有误', SYSTEM_ERR: 600, SYSTEM_ERR_MSG: '系统错误', WX_ERR_CODE: 1000, WX_OK_CODE: 200 }; var BASE_URL = 'https://apis.map.qq.com/ws/'; var URL_SEARCH = BASE_URL + 'place/v1/search'; var URL_SUGGESTION = BASE_URL + 'place/v1/suggestion'; var URL_GET_GEOCODER = BASE_URL + 'geocoder/v1/'; var URL_CITY_LIST = BASE_URL + 'district/v1/list'; var URL_AREA_LIST = BASE_URL + 'district/v1/getchildren'; var URL_DISTANCE = BASE_URL + 'distance/v1/'; var URL_DIRECTION = BASE_URL + 'direction/v1/'; var MODE = { driving: 'driving', transit: 'transit' }; var EARTH_RADIUS = 6378136.49; var Utils = { safeAdd(x, y) { var lsw = (x & 0xffff) + (y & 0xffff); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xffff) }, bitRotateLeft(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)) }, md5cmn(q, a, b, x, s, t) { return this.safeAdd(this.bitRotateLeft(this.safeAdd(this.safeAdd(a, q), this.safeAdd(x, t)), s), b) }, md5ff(a, b, c, d, x, s, t) { return this.md5cmn((b & c) | (~b & d), a, b, x, s, t) }, md5gg(a, b, c, d, x, s, t) { return this.md5cmn((b & d) | (c & ~d), a, b, x, s, t) }, md5hh(a, b, c, d, x, s, t) { return this.md5cmn(b ^ c ^ d, a, b, x, s, t) }, md5ii(a, b, c, d, x, s, t) { return this.md5cmn(c ^ (b | ~d), a, b, x, s, t) }, binlMD5(x, len) { x[len >> 5] |= 0x80 << (len % 32); x[((len + 64) >>> 9 << 4) + 14] = len; var i; var olda; var oldb; var oldc; var oldd; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for (i = 0; i < x.length; i += 16) { olda = a; oldb = b; oldc = c; oldd = d; a = this.md5ff(a, b, c, d, x[i], 7, -680876936); d = this.md5ff(d, a, b, c, x[i + 1], 12, -389564586); c = this.md5ff(c, d, a, b, x[i + 2], 17, 606105819); b = this.md5ff(b, c, d, a, x[i + 3], 22, -1044525330); a = this.md5ff(a, b, c, d, x[i + 4], 7, -176418897); d = this.md5ff(d, a, b, c, x[i + 5], 12, 1200080426); c = this.md5ff(c, d, a, b, x[i + 6], 17, -1473231341); b = this.md5ff(b, c, d, a, x[i + 7], 22, -45705983); a = this.md5ff(a, b, c, d, x[i + 8], 7, 1770035416); d = this.md5ff(d, a, b, c, x[i + 9], 12, -1958414417); c = this.md5ff(c, d, a, b, x[i + 10], 17, -42063); b = this.md5ff(b, c, d, a, x[i + 11], 22, -1990404162); a = this.md5ff(a, b, c, d, x[i + 12], 7, 1804603682); d = this.md5ff(d, a, b, c, x[i + 13], 12, -40341101); c = this.md5ff(c, d, a, b, x[i + 14], 17, -1502002290); b = this.md5ff(b, c, d, a, x[i + 15], 22, 1236535329); a = this.md5gg(a, b, c, d, x[i + 1], 5, -165796510); d = this.md5gg(d, a, b, c, x[i + 6], 9, -1069501632); c = this.md5gg(c, d, a, b, x[i + 11], 14, 643717713); b = this.md5gg(b, c, d, a, x[i], 20, -373897302); a = this.md5gg(a, b, c, d, x[i + 5], 5, -701558691); d = this.md5gg(d, a, b, c, x[i + 10], 9, 38016083); c = this.md5gg(c, d, a, b, x[i + 15], 14, -660478335); b = this.md5gg(b, c, d, a, x[i + 4], 20, -405537848); a = this.md5gg(a, b, c, d, x[i + 9], 5, 568446438); d = this.md5gg(d, a, b, c, x[i + 14], 9, -1019803690); c = this.md5gg(c, d, a, b, x[i + 3], 14, -187363961); b = this.md5gg(b, c, d, a, x[i + 8], 20, 1163531501); a = this.md5gg(a, b, c, d, x[i + 13], 5, -1444681467); d = this.md5gg(d, a, b, c, x[i + 2], 9, -51403784); c = this.md5gg(c, d, a, b, x[i + 7], 14, 1735328473); b = this.md5gg(b, c, d, a, x[i + 12], 20, -1926607734); a = this.md5hh(a, b, c, d, x[i + 5], 4, -378558); d = this.md5hh(d, a, b, c, x[i + 8], 11, -2022574463); c = this.md5hh(c, d, a, b, x[i + 11], 16, 1839030562); b = this.md5hh(b, c, d, a, x[i + 14], 23, -35309556); a = this.md5hh(a, b, c, d, x[i + 1], 4, -1530992060); d = this.md5hh(d, a, b, c, x[i + 4], 11, 1272893353); c = this.md5hh(c, d, a, b, x[i + 7], 16, -155497632); b = this.md5hh(b, c, d, a, x[i + 10], 23, -1094730640); a = this.md5hh(a, b, c, d, x[i + 13], 4, 681279174); d = this.md5hh(d, a, b, c, x[i], 11, -358537222); c = this.md5hh(c, d, a, b, x[i + 3], 16, -722521979); b = this.md5hh(b, c, d, a, x[i + 6], 23, 76029189); a = this.md5hh(a, b, c, d, x[i + 9], 4, -640364487); d = this.md5hh(d, a, b, c, x[i + 12], 11, -421815835); c = this.md5hh(c, d, a, b, x[i + 15], 16, 530742520); b = this.md5hh(b, c, d, a, x[i + 2], 23, -995338651); a = this.md5ii(a, b, c, d, x[i], 6, -198630844); d = this.md5ii(d, a, b, c, x[i + 7], 10, 1126891415); c = this.md5ii(c, d, a, b, x[i + 14], 15, -1416354905); b = this.md5ii(b, c, d, a, x[i + 5], 21, -57434055); a = this.md5ii(a, b, c, d, x[i + 12], 6, 1700485571); d = this.md5ii(d, a, b, c, x[i + 3], 10, -1894986606); c = this.md5ii(c, d, a, b, x[i + 10], 15, -1051523); b = this.md5ii(b, c, d, a, x[i + 1], 21, -2054922799); a = this.md5ii(a, b, c, d, x[i + 8], 6, 1873313359); d = this.md5ii(d, a, b, c, x[i + 15], 10, -30611744); c = this.md5ii(c, d, a, b, x[i + 6], 15, -1560198380); b = this.md5ii(b, c, d, a, x[i + 13], 21, 1309151649); a = this.md5ii(a, b, c, d, x[i + 4], 6, -145523070); d = this.md5ii(d, a, b, c, x[i + 11], 10, -1120210379); c = this.md5ii(c, d, a, b, x[i + 2], 15, 718787259); b = this.md5ii(b, c, d, a, x[i + 9], 21, -343485551); a = this.safeAdd(a, olda); b = this.safeAdd(b, oldb); c = this.safeAdd(c, oldc); d = this.safeAdd(d, oldd) } return [a, b, c, d] }, binl2rstr(input) { var i; var output = ''; var length32 = input.length * 32; for (i = 0; i < length32; i += 8) { output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff) } return output }, rstr2binl(input) { var i; var output = []; output[(input.length >> 2) - 1] = undefined; for (i = 0; i < output.length; i += 1) { output[i] = 0 } var length8 = input.length * 8; for (i = 0; i < length8; i += 8) { output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32) } return output }, rstrMD5(s) { return this.binl2rstr(this.binlMD5(this.rstr2binl(s), s.length * 8)) }, rstrHMACMD5(key, data) { var i; var bkey = this.rstr2binl(key); var ipad = []; var opad = []; var hash; ipad[15] = opad[15] = undefined; if (bkey.length > 16) { bkey = this.binlMD5(bkey, key.length * 8) } for (i = 0; i < 16; i += 1) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5c5c5c5c } hash = this.binlMD5(ipad.concat(this.rstr2binl(data)), 512 + data.length * 8); return this.binl2rstr(this.binlMD5(opad.concat(hash), 512 + 128)) }, rstr2hex(input) { var hexTab = '0123456789abcdef'; var output = ''; var x; var i; for (i = 0; i < input.length; i += 1) { x = input.charCodeAt(i); output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f) } return output }, str2rstrUTF8(input) { return unescape(encodeURIComponent(input)) }, rawMD5(s) { return this.rstrMD5(this.str2rstrUTF8(s)) }, hexMD5(s) { return this.rstr2hex(this.rawMD5(s)) }, rawHMACMD5(k, d) { return this.rstrHMACMD5(this.str2rstrUTF8(k), str2rstrUTF8(d)) }, hexHMACMD5(k, d) { return this.rstr2hex(this.rawHMACMD5(k, d)) }, md5(string, key, raw) { if (!key) { if (!raw) { return this.hexMD5(string) } return this.rawMD5(string) } if (!raw) { return this.hexHMACMD5(key, string) } return this.rawHMACMD5(key, string) }, getSig(requestParam, sk, feature, mode) { var sig = null; var requestArr = []; Object.keys(requestParam).sort().forEach(function (key) { requestArr.push(key + '=' + requestParam[key]) }); if (feature == 'search') { sig = '/ws/place/v1/search?' + requestArr.join('&') + sk } if (feature == 'suggest') { sig = '/ws/place/v1/suggestion?' + requestArr.join('&') + sk } if (feature == 'reverseGeocoder') { sig = '/ws/geocoder/v1/?' + requestArr.join('&') + sk } if (feature == 'geocoder') { sig = '/ws/geocoder/v1/?' + requestArr.join('&') + sk } if (feature == 'getCityList') { sig = '/ws/district/v1/list?' + requestArr.join('&') + sk } if (feature == 'getDistrictByCityId') { sig = '/ws/district/v1/getchildren?' + requestArr.join('&') + sk } if (feature == 'calculateDistance') { sig = '/ws/distance/v1/?' + requestArr.join('&') + sk } if (feature == 'direction') { sig = '/ws/direction/v1/' + mode + '?' + requestArr.join('&') + sk } sig = this.md5(sig); return sig }, location2query(data) { if (typeof data == 'string') { return data } var query = ''; for (var i = 0; i < data.length; i++) { var d = data[i]; if (!!query) { query += ';' } if (d.location) { query = query + d.location.lat + ',' + d.location.lng } if (d.latitude && d.longitude) { query = query + d.latitude + ',' + d.longitude } } return query }, rad(d) { return d * Math.PI / 180.0 }, getEndLocation(location) { var to = location.split(';'); var endLocation = []; for (var i = 0; i < to.length; i++) { endLocation.push({ lat: parseFloat(to[i].split(',')[0]), lng: parseFloat(to[i].split(',')[1]) }) } return endLocation }, getDistance(latFrom, lngFrom, latTo, lngTo) { var radLatFrom = this.rad(latFrom); var radLatTo = this.rad(latTo); var a = radLatFrom - radLatTo; var b = this.rad(lngFrom) - this.rad(lngTo); var distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2))); distance = distance * EARTH_RADIUS; distance = Math.round(distance * 10000) / 10000; return parseFloat(distance.toFixed(0)) }, getWXLocation(success, fail, complete) { wx.getLocation({ type: 'gcj02', success: success, fail: fail, complete: complete }) }, getLocationParam(location) { if (typeof location == 'string') { var locationArr = location.split(','); if (locationArr.length === 2) { location = { latitude: location.split(',')[0], longitude: location.split(',')[1] } } else { location = {} } } return location }, polyfillParam(param) { param.success = param.success || function () { }; param.fail = param.fail || function () { }; param.complete = param.complete || function () { } }, checkParamKeyEmpty(param, key) { if (!param[key]) { var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + key + '参数格式有误'); param.fail(errconf); param.complete(errconf); return true } return false }, checkKeyword(param) { return !this.checkParamKeyEmpty(param, 'keyword') }, checkLocation(param) { var location = this.getLocationParam(param.location); if (!location || !location.latitude || !location.longitude) { var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + ' location参数格式有误'); param.fail(errconf); param.complete(errconf); return false } return true }, buildErrorConfig(errCode, errMsg) { return { status: errCode, message: errMsg } }, handleData(param, data, feature) { if (feature == 'search') { var searchResult = data.data; var searchSimplify = []; for (var i = 0; i < searchResult.length; i++) { searchSimplify.push({ id: searchResult[i].id || null, title: searchResult[i].title || null, latitude: searchResult[i].location && searchResult[i].location.lat || null, longitude: searchResult[i].location && searchResult[i].location.lng || null, address: searchResult[i].address || null, category: searchResult[i].category || null, tel: searchResult[i].tel || null, adcode: searchResult[i].ad_info && searchResult[i].ad_info.adcode || null, city: searchResult[i].ad_info && searchResult[i].ad_info.city || null, district: searchResult[i].ad_info && searchResult[i].ad_info.district || null, province: searchResult[i].ad_info && searchResult[i].ad_info.province || null }) } param.success(data, { searchResult: searchResult, searchSimplify: searchSimplify }) } else if (feature == 'suggest') { var suggestResult = data.data; var suggestSimplify = []; for (var i = 0; i < suggestResult.length; i++) { suggestSimplify.push({ adcode: suggestResult[i].adcode || null, address: suggestResult[i].address || null, category: suggestResult[i].category || null, city: suggestResult[i].city || null, district: suggestResult[i].district || null, id: suggestResult[i].id || null, latitude: suggestResult[i].location && suggestResult[i].location.lat || null, longitude: suggestResult[i].location && suggestResult[i].location.lng || null, province: suggestResult[i].province || null, title: suggestResult[i].title || null, type: suggestResult[i].type || null }) } param.success(data, { suggestResult: suggestResult, suggestSimplify: suggestSimplify }) } else if (feature == 'reverseGeocoder') { var reverseGeocoderResult = data.result; var reverseGeocoderSimplify = { address: reverseGeocoderResult.address || null, latitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lat || null, longitude: reverseGeocoderResult.location && reverseGeocoderResult.location.lng || null, adcode: reverseGeocoderResult.ad_info && reverseGeocoderResult.ad_info.adcode || null, city: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.city || null, district: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.district || null, nation: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.nation || null, province: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.province || null, street: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street || null, street_number: reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street_number || null, recommend: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.recommend || null, rough: reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.rough || null }; if (reverseGeocoderResult.pois) { var pois = reverseGeocoderResult.pois; var poisSimplify = []; for (var i = 0; i < pois.length; i++) { poisSimplify.push({ id: pois[i].id || null, title: pois[i].title || null, latitude: pois[i].location && pois[i].location.lat || null, longitude: pois[i].location && pois[i].location.lng || null, address: pois[i].address || null, category: pois[i].category || null, adcode: pois[i].ad_info && pois[i].ad_info.adcode || null, city: pois[i].ad_info && pois[i].ad_info.city || null, district: pois[i].ad_info && pois[i].ad_info.district || null, province: pois[i].ad_info && pois[i].ad_info.province || null }) } param.success(data, { reverseGeocoderResult: reverseGeocoderResult, reverseGeocoderSimplify: reverseGeocoderSimplify, pois: pois, poisSimplify: poisSimplify }) } else { param.success(data, { reverseGeocoderResult: reverseGeocoderResult, reverseGeocoderSimplify: reverseGeocoderSimplify }) } } else if (feature == 'geocoder') { var geocoderResult = data.result; var geocoderSimplify = { title: geocoderResult.title || null, latitude: geocoderResult.location && geocoderResult.location.lat || null, longitude: geocoderResult.location && geocoderResult.location.lng || null, adcode: geocoderResult.ad_info && geocoderResult.ad_info.adcode || null, province: geocoderResult.address_components && geocoderResult.address_components.province || null, city: geocoderResult.address_components && geocoderResult.address_components.city || null, district: geocoderResult.address_components && geocoderResult.address_components.district || null, street: geocoderResult.address_components && geocoderResult.address_components.street || null, street_number: geocoderResult.address_components && geocoderResult.address_components.street_number || null, level: geocoderResult.level || null }; param.success(data, { geocoderResult: geocoderResult, geocoderSimplify: geocoderSimplify }) } else if (feature == 'getCityList') { var provinceResult = data.result[0]; var cityResult = data.result[1]; var districtResult = data.result[2]; param.success(data, { provinceResult: provinceResult, cityResult: cityResult, districtResult: districtResult }) } else if (feature == 'getDistrictByCityId') { var districtByCity = data.result[0]; param.success(data, districtByCity) } else if (feature == 'calculateDistance') { var calculateDistanceResult = data.result.elements; var distance = []; for (var i = 0; i < calculateDistanceResult.length; i++) { distance.push(calculateDistanceResult[i].distance) } param.success(data, { calculateDistanceResult: calculateDistanceResult, distance: distance }) } else if (feature == 'direction') { var direction = data.result.routes; param.success(data, direction) } else { param.success(data) } }, buildWxRequestConfig(param, options, feature) { var that = this; options.header = { "content-type": "application/json" }; options.method = 'GET'; options.success = function (res) { var data = res.data; if (data.status === 0) { that.handleData(param, data, feature) } else { param.fail(data) } }; options.fail = function (res) { res.statusCode = ERROR_CONF.WX_ERR_CODE; param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)) }; options.complete = function (res) { var statusCode = +res.statusCode; switch (statusCode) { case ERROR_CONF.WX_ERR_CODE: { param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)); break } case ERROR_CONF.WX_OK_CODE: { var data = res.data; if (data.status === 0) { param.complete(data) } else { param.complete(that.buildErrorConfig(data.status, data.message)) } break } default: { param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR, ERROR_CONF.SYSTEM_ERR_MSG)) } } }; return options }, locationProcess(param, locationsuccess, locationfail, locationcomplete) { var that = this; locationfail = locationfail || function (res) { res.statusCode = ERROR_CONF.WX_ERR_CODE; param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)) }; locationcomplete = locationcomplete || function (res) { if (res.statusCode == ERROR_CONF.WX_ERR_CODE) { param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg)) } }; if (!param.location) { that.getWXLocation(locationsuccess, locationfail, locationcomplete) } else if (that.checkLocation(param)) { var location = Utils.getLocationParam(param.location); locationsuccess(location) } } }; class QQMapWX { constructor(options) { if (!options.key) { throw Error('key值不能为空') } this.key = options.key }; search(options) { var that = this; options = options || {}; Utils.polyfillParam(options); if (!Utils.checkKeyword(options)) { return } var requestParam = { keyword: options.keyword, orderby: options.orderby || '_distance', page_size: options.page_size || 10, page_index: options.page_index || 1, output: 'json', key: that.key }; if (options.address_format) { requestParam.address_format = options.address_format } if (options.filter) { requestParam.filter = options.filter } var distance = options.distance || "1000"; var auto_extend = options.auto_extend || 1; var region = null; var rectangle = null; if (options.region) { region = options.region } if (options.rectangle) { rectangle = options.rectangle } var locationsuccess = function (result) { if (region && !rectangle) { requestParam.boundary = "region(" + region + "," + auto_extend + "," + result.latitude + "," + result.longitude + ")"; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'search') } } else if (rectangle && !region) { requestParam.boundary = "rectangle(" + rectangle + ")"; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'search') } } else { requestParam.boundary = "nearby(" + result.latitude + "," + result.longitude + "," + distance + "," + auto_extend + ")"; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'search') } } wx.request(Utils.buildWxRequestConfig(options, { url: URL_SEARCH, data: requestParam }, 'search')) }; Utils.locationProcess(options, locationsuccess) }; getSuggestion(options) { var that = this; options = options || {}; Utils.polyfillParam(options); if (!Utils.checkKeyword(options)) { return } var requestParam = { keyword: options.keyword, region: options.region || '全国', region_fix: options.region_fix || 0, policy: options.policy || 0, page_size: options.page_size || 10, page_index: options.page_index || 1, get_subpois: options.get_subpois || 0, output: 'json', key: that.key }; if (options.address_format) { requestParam.address_format = options.address_format } if (options.filter) { requestParam.filter = options.filter } if (options.location) { var locationsuccess = function (result) { requestParam.location = result.latitude + ',' + result.longitude; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'suggest') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_SUGGESTION, data: requestParam }, "suggest")) }; Utils.locationProcess(options, locationsuccess) } else { if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'suggest') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_SUGGESTION, data: requestParam }, "suggest")) } }; reverseGeocoder(options) { var that = this; options = options || {}; Utils.polyfillParam(options); var requestParam = { coord_type: options.coord_type || 5, get_poi: options.get_poi || 0, output: 'json', key: that.key }; if (options.poi_options) { requestParam.poi_options = options.poi_options } var locationsuccess = function (result) { requestParam.location = result.latitude + ',' + result.longitude; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'reverseGeocoder') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_GET_GEOCODER, data: requestParam }, 'reverseGeocoder')) }; Utils.locationProcess(options, locationsuccess) }; geocoder(options) { var that = this; options = options || {}; Utils.polyfillParam(options); if (Utils.checkParamKeyEmpty(options, 'address')) { return } var requestParam = { address: options.address, output: 'json', key: that.key }; if (options.region) { requestParam.region = options.region } if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'geocoder') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_GET_GEOCODER, data: requestParam }, 'geocoder')) }; getCityList(options) { var that = this; options = options || {}; Utils.polyfillParam(options); var requestParam = { output: 'json', key: that.key }; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'getCityList') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_CITY_LIST, data: requestParam }, 'getCityList')) }; getDistrictByCityId(options) { var that = this; options = options || {}; Utils.polyfillParam(options); if (Utils.checkParamKeyEmpty(options, 'id')) { return } var requestParam = { id: options.id || '', output: 'json', key: that.key }; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'getDistrictByCityId') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_AREA_LIST, data: requestParam }, 'getDistrictByCityId')) }; calculateDistance(options) { var that = this; options = options || {}; Utils.polyfillParam(options); if (Utils.checkParamKeyEmpty(options, 'to')) { return } var requestParam = { mode: options.mode || 'walking', to: Utils.location2query(options.to), output: 'json', key: that.key }; if (options.from) { options.location = options.from } if (requestParam.mode == 'straight') { var locationsuccess = function (result) { var locationTo = Utils.getEndLocation(requestParam.to); var data = { message: "query ok", result: { elements: [] }, status: 0 }; for (var i = 0; i < locationTo.length; i++) { data.result.elements.push({ distance: Utils.getDistance(result.latitude, result.longitude, locationTo[i].lat, locationTo[i].lng), duration: 0, from: { lat: result.latitude, lng: result.longitude }, to: { lat: locationTo[i].lat, lng: locationTo[i].lng } }) } var calculateResult = data.result.elements; var distanceResult = []; for (var i = 0; i < calculateResult.length; i++) { distanceResult.push(calculateResult[i].distance) } return options.success(data, { calculateResult: calculateResult, distanceResult: distanceResult }) }; Utils.locationProcess(options, locationsuccess) } else { var locationsuccess = function (result) { requestParam.from = result.latitude + ',' + result.longitude; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'calculateDistance') } wx.request(Utils.buildWxRequestConfig(options, { url: URL_DISTANCE, data: requestParam }, 'calculateDistance')) }; Utils.locationProcess(options, locationsuccess) } }; direction(options) { var that = this; options = options || {}; Utils.polyfillParam(options); if (Utils.checkParamKeyEmpty(options, 'to')) { return } var requestParam = { output: 'json', key: that.key }; if (typeof options.to == 'string') { requestParam.to = options.to } else { requestParam.to = options.to.latitude + ',' + options.to.longitude } var SET_URL_DIRECTION = null; options.mode = options.mode || MODE.driving; SET_URL_DIRECTION = URL_DIRECTION + options.mode; if (options.from) { options.location = options.from } if (options.mode == MODE.driving) { if (options.from_poi) { requestParam.from_poi = options.from_poi } if (options.heading) { requestParam.heading = options.heading } if (options.speed) { requestParam.speed = options.speed } if (options.accuracy) { requestParam.accuracy = options.accuracy } if (options.road_type) { requestParam.road_type = options.road_type } if (options.to_poi) { requestParam.to_poi = options.to_poi } if (options.from_track) { requestParam.from_track = options.from_track } if (options.waypoints) { requestParam.waypoints = options.waypoints } if (options.policy) { requestParam.policy = options.policy } if (options.plate_number) { requestParam.plate_number = options.plate_number } } if (options.mode == MODE.transit) { if (options.departure_time) { requestParam.departure_time = options.departure_time } if (options.policy) { requestParam.policy = options.policy } } var locationsuccess = function (result) { requestParam.from = result.latitude + ',' + result.longitude; if (options.sig) { requestParam.sig = Utils.getSig(requestParam, options.sig, 'direction', options.mode) } wx.request(Utils.buildWxRequestConfig(options, { url: SET_URL_DIRECTION, data: requestParam }, 'direction')) }; Utils.locationProcess(options, locationsuccess) } }; module.exports = QQMapWX; \ No newline at end of file diff --git a/util/request/requestInterceptors.js b/util/request/requestInterceptors.js index 63a310d..9aa4b75 100644 --- a/util/request/requestInterceptors.js +++ b/util/request/requestInterceptors.js @@ -3,26 +3,12 @@ * @param {Object} http */ module.exports = (vm) => { - // uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作 - // // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{} - // config.data = config.data || {} - // // 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中 - // // console.log(vm.$store.state); - // return config - // }, (config) => // 可使用async await 做异步操作 - // Promise.reject(config)) - - // 请求拦截 - uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作 - // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{} + uni.$u.http.interceptors.request.use((config) => { config.data = config.data || {} - // 根据custom参数中配置的是否需要token,添加对应的请求头 - if(config?.custom?.auth) { - // 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中 - config.header.token = vm.$store.state.user.token - } - return config - }, config => { // 可使用async await 做异步操作 + config.header['X-Access-Token'] = uni.getStorageSync('token'); + config.header['Content-Type'] = 'application/json' + return config + }, config => { return Promise.reject(config) }) } diff --git a/util/request/responseInterceptors.js b/util/request/responseInterceptors.js index 1144339..b9589e2 100644 --- a/util/request/responseInterceptors.js +++ b/util/request/responseInterceptors.js @@ -6,26 +6,50 @@ module.exports = (vm) => { // 响应拦截 uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/ const data = response.data - - // 自定义参数 - const custom = response.config?.custom - if (data.code !== 200) { - // 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示 - if (custom.toast !== false) { - uni.$u.toast(data.message) - } - - // 如果需要catch返回,则进行reject - if (custom?.catch) { - return Promise.reject(data) - } else { - // 否则返回一个pending中的promise,请求不会进入catch中 - return new Promise(() => { }) - } + console.info('interceptorsresponse',data) + if (data.code == 200) { + return Promise.resolve(data); + }else if(data.code === 401){ + uni.showToast({ + icon:"none", + title:data.message + }) + uni.removeStorageSync('token') + uni.removeStorageSync('userInfo') + uni.navigateTo({ + url:"/pages/auth/index" + }) + return; + }else if(data.code === 500 && (data.message == '操作失败,token非法无效!' || data.message == '操作失败,用户不存在!')){ + uni.$u.toast(data.message) + uni.showToast({ + icon:"none", + title:data.message + }) + uni.removeStorageSync('token') + uni.removeStorageSync('userInfo') + uni.navigateTo({ + url:"/pages/auth/index" + }) + return; + }else{ + uni.showToast({ + icon:"none", + title:data.message + }) + return Promise.reject(data) } - return data.data === undefined ? {} : data.data }, (response) => { - // 对响应错误做点什么 (statusCode !== 200) + const data = response.data + console.info('responseresponse',data) + if(data.code === 401){ + uni.removeStorageSync('token') + uni.removeStorageSync('userInfo') + uni.navigateTo({ + url:"/pages/auth/index" + }) + return; + } return Promise.reject(response) }) } \ No newline at end of file