diff --git a/mobile-web/.editorconfig b/mobile-web/.editorconfig new file mode 100644 index 000000000..7e3649acc --- /dev/null +++ b/mobile-web/.editorconfig @@ -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 diff --git a/mobile-web/src/api/user.js b/mobile-web/src/api/user.js index 366c25796..d0f768ddf 100644 --- a/mobile-web/src/api/user.js +++ b/mobile-web/src/api/user.js @@ -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 }) } diff --git a/mobile-web/src/config/request.js b/mobile-web/src/config/request.js index 0f79ec73f..55b4cdc30 100644 --- a/mobile-web/src/config/request.js +++ b/mobile-web/src/config/request.js @@ -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; } @@ -142,4 +210,4 @@ service.interceptors.response.use( ) -export default servicef \ No newline at end of file +export default servicef diff --git a/mobile-web/src/page/user/address/edit.vue b/mobile-web/src/page/user/address/edit.vue index da05884d4..7c62f04d1 100644 --- a/mobile-web/src/page/user/address/edit.vue +++ b/mobile-web/src/page/user/address/edit.vue @@ -1,64 +1,93 @@ - - - + + - + /> + diff --git a/mobile-web/src/page/user/address/list.vue b/mobile-web/src/page/user/address/list.vue index 5c05bc695..843140b96 100644 --- a/mobile-web/src/page/user/address/list.vue +++ b/mobile-web/src/page/user/address/list.vue @@ -1,65 +1,73 @@ - + - + v-model="chosenAddressId" + :class="isSelect?'':'hideselect'" + :list="list" + @add="onAdd" + @edit="onEdit" + @select="onSelect" + /> + diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java index dec8f0346..24055c9c0 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java @@ -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); + } } diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java index ba66ed695..275c993c2 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java @@ -22,4 +22,6 @@ public interface UserAddressService { CommonResult removeAddress(Integer userId, Integer addressId); CommonResult> addressList(Integer userId); + + CommonResult getAddress(Integer userId, Integer id); } diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/UserAddressBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/UserAddressBO.java index 2aa55f9b8..3c9ff30d1 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/UserAddressBO.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/UserAddressBO.java @@ -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; + } } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java index 39f2f4ed1..2cc008454 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java @@ -27,6 +27,9 @@ public interface UserAddressConvert { @Mappings({}) UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO); + @Mappings({}) + UserAddressBO convert(UserAddressDO userAddressDO); + @Mappings({}) List convertUserAddressBOList(List userAddressDOList); } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java index 78e755908..6529fa5c0 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java @@ -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 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); + } } diff --git a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml index 4320d07e0..baec051d8 100644 --- a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml +++ b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml @@ -9,7 +9,8 @@ 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}