Authored by jinhu.tung

fix address component url request

... ... @@ -90,10 +90,33 @@ const setDefaultAddress = (req, res) => {
});
};
/**
* 获取地址信息
* @function getAddressData
* @return { Object }
*/
const getAddressData = (req, res) => {
addressModel.getAddressData(req.params.areaId).then(result => {
if (result.code === 200) {
result.data = result.data.map((item) => {
return {
is_support: item.is_support_express,
text: item.caption,
value: item.id
};
});
res.json(result);
} else {
res.json(result);
}
});
};
module.exports = {
index,
addAddressData,
updateAddressData,
delAddressData,
setDefaultAddress
setDefaultAddress,
getAddressData
};
... ...
... ... @@ -119,10 +119,28 @@ const setDefaultAddress = (id, uid) => {
});
};
/**
* 获取地址信息
* @function getAddressData
* @return { Array } [返回带有areaId的地址数组]
* @param id
* @param caption
* @param is_support_express
*/
const getAddressData = (areaId) => {
return api.get('', {
method: 'app.address.provinces',
id: areaId || 0
}).then(result => {
return result;
});
};
module.exports = {
getAddressDataAsync: getAddressDataAsync,
addAddressData: addAddressData,
updateAddressData: updateAddressData,
delAddressData: delAddressData,
setDefaultAddress: setDefaultAddress
setDefaultAddress: setDefaultAddress,
getAddressData
};
... ...
... ... @@ -24,5 +24,6 @@ router.post('/address/add', address.addAddressData);
router.post('/address/update', address.updateAddressData);
router.post('/address/del', address.delAddressData);
router.post('/address/default', address.setDefaultAddress);
router.get('/address/areas/:areaId', address.getAddressData);
module.exports = router;
... ...
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
common = require('../common'),
dialog = require('../plugins/dialog');
var _dialog = dialog.Dialog,
... ... @@ -95,11 +96,8 @@ $(function() {
// 运行此demo
// 1. 安装 npm i -g json-server
// 2. json-server --watch mock/address.json
window.add = cascadingAddress({
el: '#address',
url: 'http://localhost:3000/areas/0',
resource: 'areas'
});
common.setCookie('uid', '8050484');
window.add = cascadingAddress({el: '#address'});
});
$('.weixin').click(function() {
... ...
... ... @@ -17,7 +17,7 @@ var $ = require('yoho-jquery');
// 默认配置
var settings = {
url: '',
url: '/me/address/areas/0',
containerClass: 'cascading-address',
levels: 3,
resources: 'areas',
... ...