Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
928255095 committed Sep 8, 2020
1 parent ed999a6 commit a27d347
Show file tree
Hide file tree
Showing 118 changed files with 3,216 additions and 3,423 deletions.
22 changes: 22 additions & 0 deletions api/applicationKey/applicationKeyApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,26 @@ export function applyApplicationKey(_obj){
}
});
})
}


export function listOwnerMachines(_objData){
return new Promise((resolve, reject) => {
request({
url: url.listOwnerMachines,
method: "GET",
data: _objData, //动态数据
success: function(res) {
if (res.statusCode == 200) {
let _machines = res.data.machines;
resolve(_machines);
return;
}
reject(res);
},
fail: function(e) {
reject(e);
}
});
})
}
36 changes: 36 additions & 0 deletions api/repair/repairApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
request
} from '../java110Request.js'
import
url
from '../../constant/url.js'

import
mapping
from '../../constant/MappingConstant.js'

/**
* 报修评价
* @param {Object} _data 评价内容
*/
export function appraiseRepair(_data) {
return new Promise((resolve, reject) => {
let moreRooms = [];
request({
url: url.appraiseRepair,
method: "POST",
data: _data, //动态数据
success: function(res) {
let _data = res.data;
if (_data.code == 0) {
resolve(_data);
return ;
}
reject(_data.msg);
},
fail: function(e) {
reject(e);
}
});
})
}
181 changes: 18 additions & 163 deletions context/Java110Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,76 +10,30 @@ const constant = require("../constant/index.js");

const factory = require("../factory/index.js");

import {getHeaders,request,requestNoAuth} from '../api/java110Request.js'

import {getCurOwner} from '../api/owner/ownerApi.js'

import {getProperty} from '../api/property/propertyApi.js'

import {onLoad} from '../api/init/initApi.js'

let util = {};
/**
* 获取请后台服务时的头信息
*/
const getHeaders = function() {

let _wAppId = uni.getStorageSync(constant.mapping.W_APP_ID);
return {
"app-id": constant.app.appId,
"transaction-id": 'util.core.wxuuid()',
"req-time": 'util.date.getDateYYYYMMDDHHMISS()',
"sign": '1234567',
"user-id": '-1',
"cookie": '_java110_token_=' + wx.getStorageSync('token'),
"Accept": '*/*',
"w-app-id":_wAppId
};
};

/**
* http 请求 加入是否登录判断
*/
const request = function(_reqObj) {
const requestObj = function(_reqObj) {

//这里判断只有在 post 方式时 放加载框
if (_reqObj.hasOwnProperty("method") && "POST" == _reqObj.method) {
uni.showLoading({
title: '加载中',
mask: true
});
_reqObj.complete = function() {
uni.hideLoading();
}
}

//白名单直接跳过检查登录
if (constant.url.NEED_NOT_LOGIN_URL.includes(_reqObj.url)) {
_reqObj.communityId = constant.mapping.HC_TEST_COMMUNITY_ID;
uni.request(_reqObj);
requestNoAuth(_reqObj);
return;
}
//校验是否登录,如果没有登录跳转至温馨提示页面
factory.login.checkSession().then(function() {
//有回话 跳转至相应页面
//重写token
_reqObj.header.cookie = '_java110_token_=' + wx.getStorageSync('token');
uni.request(_reqObj);
}, function(error) { //回话过期
// #ifdef H5
//先微信登录
factory.login.wechatRefreshToken();
// #endif

//小程序登录
// #ifdef MP-WEIXIN
factory.login.doLogin();
// #endif

// #ifdef APP-PLUS
//查询临时钥匙
let _key = wx.getStorageSync(constant.mapping.OWNER_KEY);
if (_key) {
factory.login._doLoginOwnerByKey(_key);
} else {
uni.navigateTo({
url: '/pages/showlogin/showlogin'
});
return;
}
// #endif
});
request(_reqObj);
};
/**
* 获取位置
Expand Down Expand Up @@ -176,85 +130,13 @@ const _loadArea = function(_level, _parentAreaCode, callBack = _areaList => {})

const getOwner = function(callBack = _ownerInfo => {}) {
// 从硬盘中获取 业主信息
let _ownerInfo = wx.getStorageSync(constant.mapping.OWNER_INFO);
console.log('owner', _ownerInfo);
if (_ownerInfo) {
callBack(_ownerInfo);
} else {
request({
url: constant.url.queryAppUserBindingOwner,
header: getHeaders(),
data: {},
success: function(res) {
console.log('login success');
let _json = res.data;
console.log(res);

if (_json.code == 0) {
_ownerInfo = _json.data[0];

if (_ownerInfo == null || _ownerInfo == undefined) {
callBack(null);
return;
}

if (_ownerInfo.state == '12000') {
wx.setStorageSync(constant.mapping.OWNER_INFO, _ownerInfo);
let _currentCommunityInfo = {
communityId: _ownerInfo.communityId,
communityName: _ownerInfo.communityName
};
wx.setStorageSync(constant.mapping.CURRENT_COMMUNITY_INFO, _currentCommunityInfo);
}

callBack(_json.data[0]);
}
},
fail: function(error) {
// 调用服务端登录接口失败
wx.showToast({
title: '调用接口失败'
});
console.log(error);
}
});
}
};

const getProperty = function() {
let communitInfo = getCurrentCommunity();
return new Promise((resolve, reject) => {
let _objData = {
page: 1,
row: 5,
communityId: communitInfo.communityId,
memberTypeCd: '390001200002'
};
request({
url: constant.url.listStore,
header: getHeaders(),
method: "GET",
data: _objData,
//动态数据
success: function(res) {
console.log("请求返回信息:", res);
if (res.statusCode == 200) {
resolve(res.data.stores[0]);
return;
}
reject(res.body);
},
fail: function(e) {
// 调用服务端登录接口失败
wx.showToast({
title: '调用接口失败',
icon: 'none'
});
reject(e);
}
});
getCurOwner()
.then((_owner)=>{
callBack(_owner);
})
};


/**
* 获取当前小区信息
*/
Expand Down Expand Up @@ -371,33 +253,6 @@ const navigateTo = function(_param) {
});
};

const onLoad = function(_option) {

console.log('参数打印',_option);

// #ifdef H5

let _key = _option.key;

if (_key != null && _key != undefined && _key != '') {
//根据key 去做登录
factory.login._doLoginOwnerByKey(_key);
}

let wAppId = _option.wAppId;

if (wAppId != null && wAppId != undefined && wAppId != '') {
uni.setStorageSync(constant.mapping.W_APP_ID, _option.wAppId);
}else{
wAppId = uni.getStorageInfoSync(constant.mapping.W_APP_ID)
if(wAppId != null && wAppId != undefined && wAppId != ''){
uni.setStorageSync(constant.mapping.W_APP_ID, constant.app.wAppId);
}
}


// #endif
}

module.exports = {
constant: constant,
Expand All @@ -411,7 +266,7 @@ module.exports = {
getCurrentLocation: getCurrentLocation,
getOwner: getOwner,
getCurrentCommunity: getCurrentCommunity,
request: request,
request: requestObj,
getRooms: getRooms,
getProperty: getProperty,
checkLoginStatus: checkLoginStatus,
Expand Down
62 changes: 12 additions & 50 deletions pages/applicationKeyLocation/applicationKeyLocation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@

<script>
// pages/applicationKeyLocation/applicationKeyLocation.js
const context = require("../../context/Java110Context.js");
const constant = context.constant;
import noDataPage from '@/components/no-data-page/no-data-page.vue';
import {listOwnerMachines} from '../../api/applicationKey/applicationKeyApi.js'
import {getCurOwner} from '../../api/owner/ownerApi.js'
export default {
data() {
return {
Expand All @@ -57,7 +58,7 @@
* 生命周期函数--监听页面加载
*/
onLoad: function(options) { //this._loadOwnerLocation();
context.onLoad(options);
this.vc.onLoad(options);
},
/**
Expand All @@ -72,26 +73,6 @@
this.loadOwnerLocationFun();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {},
/**
* 用户点击右上角分享
*/
Expand All @@ -100,39 +81,20 @@
loadOwnerLocationFun: function() {
let _that = this;
context.getOwner(function(_owner) {
console.log('数据执行', _owner);
getCurOwner()
.then((_owner)=>{
let _data = {
memberId: _owner.memberId,
communityId: _owner.communityId
};
_that.communityName = _owner.communityName;
_that.communityId = _owner.communityId;
context.request({
url: constant.url.listOwnerMachines,
header: context.getHeaders(),
method: "GET",
data: _data,
//动态数据
success: function(res) {
console.log('查询业主门禁', res); //成功情况下跳转
if (res.statusCode == 200) {
let _machines = res.data.machines;
_that.locations = _machines;
}
},
fail: function(e) {
wx.showToast({
title: "服务器异常了",
icon: 'none',
duration: 2000
});
}
});
});
listOwnerMachines(_data)
.then((_machines)=>{
_that.locations = _machines;
})
})
},
gotoApplyApplicationKeyPage: function() {
// 跳转至 填写信息页面
Expand Down
Loading

0 comments on commit a27d347

Please sign in to comment.