- 调通 用户商品地址

This commit is contained in:
sin 2019-04-06 18:26:57 +08:00
parent 27d3a6bba1
commit 207342187b
11 changed files with 352 additions and 105 deletions

16
mobile-web/.editorconfig Normal file
View File

@ -0,0 +1,16 @@
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab

View File

@ -18,31 +18,40 @@ export function DelFavorite(id){
export function GetAddressList(){
return request({
url: '/User/GetAddressList',
url: '/user-api/user/address/list',
method: 'get',
})
}
export function GetAddressById(id){
return request({
url: '/User/GetAddressById',
url: '/user-api/user/address/address',
method: 'get',
params: { id }
})
}
export function SaveAddress(data){
export function UpdateAddress(data){
return request({
url: '/User/SaveAddress',
method: 'post',
params: { data }
url: '/user-api/user/address/update',
method: 'PUT',
params: data
})
}
export function SaveAddress(data){
return request({
url: '/user-api/user/address/add',
method: 'POST',
params: data
})
}
export function DelAddress(data){
return request({
url: '/User/DelAddress',
method: 'post',
params: { data }
url: '/user-api/user/address/remove',
method: 'DELETE',
params: data
})
}

View File

@ -4,8 +4,74 @@ import datas from '../data/data';
import { getAccessToken } from '../utils/cache.js';
import { Dialog } from 'vant';
const serviceRouter = function(requestUrl) {
function getConfig() {
const configDev = {
'/order-api': {
prefix: '/order-api',
target: 'http://127.0.0.1:18084/order-api',
},
'/user-api': {
prefix: '/user-api',
target: 'http://127.0.0.1:18082/user-api',
},
};
const configProd = {
'/order-api': {
prefix: '/order-api',
target: 'http://127.0.0.1:18084/order-api',
},
'/user-api': {
prefix: '/user-api',
target: 'http://127.0.0.1:18082/user-api',
},
};
if (process.env.NODE_ENV == 'development') {
return configDev;
} else {
return configProd
}
}
// function doCreateServer(config) {
// // 获取请求配置文件
// const createServer = {};
// for (const configKey in config) {
// const serverPrefix = configKey;
// const {target} = config[configKey];
// // 创建服务
// createServer[serverPrefix] = axios.create({
// baseURL: target, // api 的 base_url
// timeout: 5000, // request timeout
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
// }
// });
// }
// }
const config = getConfig();
// const createServer = doCreateServer(config);
const indexOf = requestUrl.indexOf("/", 1);
const _urlPrefix = requestUrl.substring(0, indexOf);
if (!config[_urlPrefix]) {
throw new Error(`服务路由,未找到可用服务! ${requestUrl}`);
}
// if (!createServer[_urlPrefix]) {
// throw new Error("服务路由,未找到可用服务!");
// }
// const { target } = config[_urlPrefix];
// const requestServer = createServer[_urlPrefix];
// const targetRequestUrl = _requestUrl.replace(_urlPrefix, target)
// return createServer;
return config[_urlPrefix];
};
const service = axios.create({
baseURL: baseUrl, // api 的 base_url
// baseURL: baseUrl, // api 的 base_url
timeout: 5000, // request timeout
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
@ -34,6 +100,7 @@ const servicef = function (parameter) {
// };
// }
// debugger;
return service(parameter);
}
@ -46,11 +113,12 @@ service.interceptors.request.use(
// config.headers['X-Token'] = getToken()
// }
// debugger;
let url = config.url;
// 切换地址
const { target, prefix } = serviceRouter(config.url)
let url = config.url = config.url.replace(`${prefix}`, target);
// TODO 芋艿,这些 url 不用增加认证 token 。可能这么写,有点脏,后面看看咋优化下。
if (url === 'user-api/users/passport/mobile/send_register_code'
|| url === 'user-api/users/passport/mobile/register') {
if (url.indexOf('user-api/users/passport/mobile/send_register_code') != -1
|| url.indexOf('user-api/users/passport/mobile/register') != -1) {
return config;
}

View File

@ -1,64 +1,93 @@
<template>
<div>
<headerNav title="修改地址"/>
<van-address-edit
<div>
<headerNav title="修改地址"/>
<van-address-edit
:area-list="areaList"
:showDelete="showDelete"
show-set-default
@save="onSave"
@delete="onDelete"
:addressInfo="info"
/>
</div>
/>
</div>
</template>
<script>
import areaList from '../../../data/area';
import { GetAddressById,SaveAddress,DelAddress } from "../../../api/user.js";
import areaList from '../../../data/area';
import {GetAddressById, SaveAddress, UpdateAddress, DelAddress} from "../../../api/user.js";
import { AddressEdit } from 'vant';
export default {
components:{
[AddressEdit.name]:AddressEdit,
import {AddressEdit} from 'vant';
export default {
components: {
[AddressEdit.name]: AddressEdit,
},
data() {
return {
areaList,
showDelete:false,
info:{},
}
},
return {
areaList,
showDelete: false,
info: {
},
}
},
methods: {
onSave(data) {
SaveAddress(data).then(response=>{
this.$toast('保存成功');
this.$router.go(-1);
})
methods: {
onSave(data) {
const params = {
...data,
address: data.addressDetail,
areaNo: data.areaCode,
city: data.city,
county: data.county,
country: data.country,
mobile: data.tel,
name: data.name,
hasDefault: data.isDefault,
};
if (data.id !== 0) {
UpdateAddress(params).then(response => {
this.$toast('更新成功');
this.$router.go(-1);
})
} else {
SaveAddress(params).then(response => {
this.$toast('保存成功');
this.$router.go(-1);
})
}
},
onDelete(data) {
const params = {
id: data.id,
};
DelAddress(params).then(response => {
this.$toast('删除成功');
this.$router.go(-1);
})
},
},
onDelete(data) {
DelAddress(data).then(response=>{
this.$toast('删除成功');
this.$router.go(-1);
})
},
},
created:function(){
var id=this.$route.query.id;
if(id>0){
this.showDelete=true;
GetAddressById(id).then(response=>{
console.log(response);
this.info=response;
})
created: function () {
const id = this.$route.query.id;
if (id > 0) {
this.showDelete = true;
GetAddressById(id).then(response => {
this.info = {
...response,
addressDetail: response.address,
tel: response.mobile,
areaCode: response.areaNo,
isDefault: 0,
};
})
}
}
}
}
</script>
<style>
.van-picker__toolbar{
font-size: 16px;
}
.van-picker__toolbar {
font-size: 16px;
}
</style>

View File

@ -1,65 +1,73 @@
<template>
<div>
<div>
<headerNav title="我的地址"/>
<van-address-list
v-model="chosenAddressId"
:class="isSelect?'':'hideselect'"
:list="list"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</div>
v-model="chosenAddressId"
:class="isSelect?'':'hideselect'"
:list="list"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</div>
</template>
<script>
import { GetAddressList } from "../../../api/user.js";
import { AddressList } from 'vant';
export default {
components:{
[AddressList.name]:AddressList,
import {GetAddressList} from "../../../api/user.js";
import {AddressList} from 'vant';
export default {
components: {
[AddressList.name]: AddressList,
},
data() {
return {
return {
chosenAddressId: '1',
isSelect:false,
isSelect: false,
list: [],
}
}
},
methods: {
onAdd() {
this.$router.push('/user/address/edit')
},
onAdd() {
this.$router.push('/user/address/edit')
},
onEdit(item, index) {
this.$router.push('/user/address/edit?id='+item.id);
},
onSelect(item,index){
if(!this.isSelect){
return;
}
this.$emit('selectAddress',item);
this.$router.go(-1);
onEdit(item, index) {
this.$router.push('/user/address/edit?id=' + item.id);
},
onSelect(item, index) {
if (!this.isSelect) {
return;
}
this.$emit('selectAddress', item);
this.$router.go(-1);
}
},
created:function(){
this.chosenAddressId=this.$route.query.id;
this.isSelect=this.$route.query.id>0;
GetAddressList().then(response=>{
this.list=response;
})
created: function () {
this.chosenAddressId = this.$route.query.id;
this.isSelect = this.$route.query.id > 0;
GetAddressList().then(response => {
this.list = response.map(item => {
// convert data
return {
...item,
tel: item.mobile,
}
});
})
}
}
}
</script>
<style lang="less">
.hideselect{
.van-radio__input{
display: none;
.hideselect {
.van-radio__input {
display: none;
}
}
}
</style>

View File

@ -30,19 +30,19 @@ public class UserAddressController {
@PostMapping("add")
@ApiOperation(value = "用户地址-添加")
public CommonResult addAddress(@RequestBody @Validated UserAddressAddPO userAddressAddPO) {
public CommonResult addAddress(@Validated UserAddressAddPO userAddressAddPO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddPO);
userAddressAddDTO.setUserId(userId);
userAddressAddDTO.setUserId(1);
return userAddressService.addAddress(userAddressAddDTO);
}
@PutMapping("update")
@ApiOperation(value = "用户地址-更新")
public CommonResult updateAddress(@RequestBody @Validated UserAddressUpdatePO userAddressUpdatePO) {
public CommonResult updateAddress(@Validated UserAddressUpdatePO userAddressUpdatePO) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
UserAddressUpdateDTO userAddressUpdateDTO = UserAddressConvert.INSTANCE.convert(userAddressUpdatePO);
userAddressUpdateDTO.setUserId(userId);
userAddressUpdateDTO.setUserId(1);
return userAddressService.updateAddress(userAddressUpdateDTO);
}
@ -50,7 +50,7 @@ public class UserAddressController {
@ApiOperation(value = "用户地址-删除")
public CommonResult removeAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.removeAddress(userId, id);
return userAddressService.removeAddress(1, id);
}
@GetMapping("list")
@ -59,4 +59,11 @@ public class UserAddressController {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.addressList(1);
}
@GetMapping("address")
@ApiOperation(value = "获取地址")
public CommonResult getAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.getAddress(1, id);
}
}

View File

@ -22,4 +22,6 @@ public interface UserAddressService {
CommonResult removeAddress(Integer userId, Integer addressId);
CommonResult<List<UserAddressBO>> addressList(Integer userId);
CommonResult<UserAddressBO> getAddress(Integer userId, Integer id);
}

View File

@ -5,4 +5,96 @@ package cn.iocoder.mall.user.api.bo;
* @time 2019-04-06 13:28
*/
public class UserAddressBO {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
@Override
public String toString() {
return "UserAddressBO{" +
"id=" + id +
", userId=" + userId +
", areaNo='" + areaNo + '\'' +
", name='" + name + '\'' +
", mobile='" + mobile + '\'' +
", address='" + address + '\'' +
'}';
}
public Integer getId() {
return id;
}
public UserAddressBO setId(Integer id) {
this.id = id;
return this;
}
public Integer getUserId() {
return userId;
}
public UserAddressBO setUserId(Integer userId) {
this.userId = userId;
return this;
}
public String getAreaNo() {
return areaNo;
}
public UserAddressBO setAreaNo(String areaNo) {
this.areaNo = areaNo;
return this;
}
public String getName() {
return name;
}
public UserAddressBO setName(String name) {
this.name = name;
return this;
}
public String getMobile() {
return mobile;
}
public UserAddressBO setMobile(String mobile) {
this.mobile = mobile;
return this;
}
public String getAddress() {
return address;
}
public UserAddressBO setAddress(String address) {
this.address = address;
return this;
}
}

View File

@ -27,6 +27,9 @@ public interface UserAddressConvert {
@Mappings({})
UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO);
@Mappings({})
UserAddressBO convert(UserAddressDO userAddressDO);
@Mappings({})
List<UserAddressBO> convertUserAddressBOList(List<UserAddressDO> userAddressDOList);
}

View File

@ -44,7 +44,7 @@ public class UserAddressServiceImpl implements UserAddressService {
.selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId());
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
return CommonResult.success(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
if (userAddress == null) {
@ -89,4 +89,16 @@ public class UserAddressServiceImpl implements UserAddressService {
return CommonResult.success(userAddressBOList);
}
@Override
public CommonResult<UserAddressBO> getAddress(Integer userId, Integer id) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, id);
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress);
return CommonResult.success(userAddressBO);
}
}

View File

@ -9,7 +9,8 @@
<insert id="insert" parameterType="UserAddressDO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_address (
user_id, area_no, `name`, mobile, address
user_id, area_no, `name`, mobile, address,
create_time, update_time, deleted
) VALUES (
#{userId}, #{areaNo}, #{name}, #{mobile}, #{address},
#{createTime}, #{updateTime}, #{deleted}