init
This commit is contained in:
158
miniprogram/pages/user/components/t-location/index.js
Normal file
158
miniprogram/pages/user/components/t-location/index.js
Normal file
@@ -0,0 +1,158 @@
|
||||
import { getPermission } from '../../../../utils/getPermission';
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
import { addressParse } from '../../../../utils/addressParse';
|
||||
import { resolveAddress, rejectAddress } from '../../../../services/address/list';
|
||||
|
||||
Component({
|
||||
externalClasses: ['t-class'],
|
||||
properties: {
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
navigateUrl: {
|
||||
type: String,
|
||||
},
|
||||
navigateEvent: {
|
||||
type: String,
|
||||
},
|
||||
isCustomStyle: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
isDisabledBtn: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
isOrderSure: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getWxLocation() {
|
||||
console.log('[微信地址导入] 开始获取微信地址');
|
||||
console.log('[微信地址导入] 按钮状态检查:', {
|
||||
isDisabledBtn: this.properties.isDisabledBtn,
|
||||
isOrderSure: this.properties.isOrderSure,
|
||||
navigateUrl: this.properties.navigateUrl
|
||||
});
|
||||
|
||||
if (this.properties.isDisabledBtn) {
|
||||
console.log('[微信地址导入] 按钮被禁用,退出');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[微信地址导入] 开始获取通讯地址权限');
|
||||
getPermission({ code: 'scope.address', name: '通讯地址' }).then(() => {
|
||||
console.log('[微信地址导入] 权限获取成功,调用wx.chooseAddress');
|
||||
|
||||
wx.chooseAddress({
|
||||
success: async (options) => {
|
||||
console.log('[微信地址导入] wx.chooseAddress成功回调');
|
||||
console.log('[微信地址导入] 原始地址数据:', options);
|
||||
|
||||
const { provinceName, cityName, countyName, detailInfo, userName, telNumber } = options;
|
||||
|
||||
console.log('[微信地址导入] 解析后的地址字段:', {
|
||||
provinceName,
|
||||
cityName,
|
||||
countyName,
|
||||
detailInfo,
|
||||
userName,
|
||||
telNumber
|
||||
});
|
||||
|
||||
// 移除手机号验证逻辑,允许导入任何格式的手机号
|
||||
console.log('[微信地址导入] 跳过手机号验证,直接使用微信提供的手机号:', telNumber);
|
||||
|
||||
const target = {
|
||||
name: userName,
|
||||
phone: telNumber,
|
||||
countryName: '中国',
|
||||
countryCode: 'chn',
|
||||
detailAddress: detailInfo,
|
||||
provinceName: provinceName,
|
||||
cityName: cityName,
|
||||
districtName: countyName,
|
||||
isDefault: false,
|
||||
isOrderSure: this.properties.isOrderSure,
|
||||
};
|
||||
|
||||
console.log('[微信地址导入] 构建目标地址对象:', target);
|
||||
|
||||
try {
|
||||
console.log('[微信地址导入] 开始地址解析:', { provinceName, cityName, countyName });
|
||||
const { provinceCode, cityCode, districtCode } = await addressParse(provinceName, cityName, countyName);
|
||||
|
||||
console.log('[微信地址导入] 地址解析成功:', { provinceCode, cityCode, districtCode });
|
||||
|
||||
const params = Object.assign(target, {
|
||||
provinceCode,
|
||||
cityCode,
|
||||
districtCode,
|
||||
});
|
||||
|
||||
console.log('[微信地址导入] 最终地址参数:', params);
|
||||
|
||||
if (this.properties.isOrderSure) {
|
||||
console.log('[微信地址导入] 订单确认模式,调用onHandleSubmit');
|
||||
this.onHandleSubmit(params);
|
||||
} else if (this.properties.navigateUrl != '') {
|
||||
console.log('[微信地址导入] 导航模式,跳转到:', this.properties.navigateUrl);
|
||||
const { navigateEvent } = this.properties;
|
||||
this.triggerEvent('navigate');
|
||||
wx.navigateTo({
|
||||
url: this.properties.navigateUrl,
|
||||
success: function (res) {
|
||||
console.log('[微信地址导入] 页面跳转成功,发送事件:', navigateEvent);
|
||||
res.eventChannel.emit(navigateEvent, params);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log('[微信地址导入] 触发change事件');
|
||||
this.triggerEvent('change', params);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[微信地址导入] 地址解析失败:', error);
|
||||
wx.showToast({ title: '地址解析出错,请稍后再试', icon: 'none' });
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.warn('[微信地址导入] 用户取消选择或选择失败:', err);
|
||||
},
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error('[微信地址导入] 权限获取失败:', error);
|
||||
});
|
||||
},
|
||||
|
||||
async queryAddress(addressId) {
|
||||
try {
|
||||
const { data } = await apis.userInfo.queryAddress({ addressId });
|
||||
return data.userAddressVO;
|
||||
} catch (err) {
|
||||
console.error('查询地址错误', err);
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
findPage(pageRouteUrl) {
|
||||
const currentRoutes = getCurrentPages().map((v) => v.route);
|
||||
return currentRoutes.indexOf(pageRouteUrl);
|
||||
},
|
||||
|
||||
async onHandleSubmit(params) {
|
||||
try {
|
||||
const orderPageDeltaNum = this.findPage('pages/order/order-confirm/index');
|
||||
if (orderPageDeltaNum > -1) {
|
||||
wx.navigateBack({ delta: 1 });
|
||||
resolveAddress(params);
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
rejectAddress(params);
|
||||
console.error(err);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
8
miniprogram/pages/user/components/t-location/index.json
Normal file
8
miniprogram/pages/user/components/t-location/index.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-toast": "tdesign-miniprogram/toast/toast"
|
||||
}
|
||||
}
|
||||
16
miniprogram/pages/user/components/t-location/index.wxml
Normal file
16
miniprogram/pages/user/components/t-location/index.wxml
Normal file
@@ -0,0 +1,16 @@
|
||||
<view class="wx-address t-class" bind:tap="getWxLocation">
|
||||
<block wx:if="{{isCustomStyle}}">
|
||||
<view class="wx-address-custom">
|
||||
<t-icon prefix="wr" t-class="weixin" color="#0ABF5B" name="wechat" size="48rpx" />
|
||||
<text>{{title}}</text>
|
||||
</view>
|
||||
<slot />
|
||||
</block>
|
||||
<block wx:else>
|
||||
<t-cell title="{{title}}" title-class="cell__title" wr-class="cell" border="{{false}}">
|
||||
<t-icon t-class="weixin" slot="icon" color="#0ABF5B" name="logo-windows" size="48rpx" />
|
||||
<t-icon slot="right-icon" name="chevron-right" class="custom-icon" color="#bbb" />
|
||||
</t-cell>
|
||||
</block>
|
||||
</view>
|
||||
<t-toast id="t-toast" />
|
||||
19
miniprogram/pages/user/components/t-location/index.wxss
Normal file
19
miniprogram/pages/user/components/t-location/index.wxss
Normal file
@@ -0,0 +1,19 @@
|
||||
.wx-address .weixin {
|
||||
display: inline-block;
|
||||
font-size: 48rpx !important;
|
||||
margin-right: 20rpx;
|
||||
font-weight: normal;
|
||||
}
|
||||
.wx-address .cell {
|
||||
padding: 32rpx 30rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.wx-address .cell__title {
|
||||
font-size: 30rpx;
|
||||
color: #333333;
|
||||
}
|
||||
.wx-address-custom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
50
miniprogram/pages/user/components/ui-address-item/index.js
Normal file
50
miniprogram/pages/user/components/ui-address-item/index.js
Normal file
@@ -0,0 +1,50 @@
|
||||
Component({
|
||||
options: {
|
||||
addGlobalClass: true,
|
||||
multipleSlots: true,
|
||||
},
|
||||
properties: {
|
||||
address: {
|
||||
type: Object,
|
||||
value: {},
|
||||
},
|
||||
customIcon: {
|
||||
type: String,
|
||||
value: 'edit-1',
|
||||
},
|
||||
extraSpace: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
},
|
||||
isDrawLine: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
},
|
||||
},
|
||||
externalClasses: [
|
||||
'item-wrapper-class',
|
||||
'title-class',
|
||||
'default-tag-class',
|
||||
'normal-tag-class',
|
||||
'address-info-class',
|
||||
'delete-class',
|
||||
],
|
||||
methods: {
|
||||
onDelete(e) {
|
||||
const { item } = e.currentTarget.dataset;
|
||||
this.triggerEvent('onDelete', item);
|
||||
},
|
||||
onSelect(e) {
|
||||
const { item } = e.currentTarget.dataset;
|
||||
this.triggerEvent('onSelect', item);
|
||||
},
|
||||
onEdit(e) {
|
||||
const { item } = e.currentTarget.dataset;
|
||||
this.triggerEvent('onEdit', item);
|
||||
},
|
||||
onSetDefault(e) {
|
||||
const { item } = e.currentTarget.dataset;
|
||||
this.triggerEvent('onSetDefault', item);
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-tag": "tdesign-miniprogram/tag/tag",
|
||||
"t-swipe-cell": "tdesign-miniprogram/swipe-cell/swipe-cell"
|
||||
}
|
||||
}
|
||||
37
miniprogram/pages/user/components/ui-address-item/index.wxml
Normal file
37
miniprogram/pages/user/components/ui-address-item/index.wxml
Normal file
@@ -0,0 +1,37 @@
|
||||
<wxs module="phoneReg">
|
||||
var toHide = function(array) { var mphone = array.substring(0, 3) + '****' + array.substring(7); return mphone; }
|
||||
module.exports.toHide = toHide;
|
||||
</wxs>
|
||||
<view class="address-item-wrapper item-wrapper-class">
|
||||
<t-swipe-cell class="swipe-out">
|
||||
<view class="address {{isDrawLine ? 'draw-line' : ''}}" bindtap="onSelect" data-item="{{address}}">
|
||||
<view class="address-left" wx:if="{{extraSpace}}">
|
||||
<t-icon wx:if="{{address.checked}}" name="check" color="#FA4126" class-prefix="{{classPrefix}}" size="46rpx" />
|
||||
</view>
|
||||
<view class="address-content">
|
||||
<view class="title title-class">
|
||||
<text class="text-style">{{address.name}}</text>
|
||||
<text>{{phoneReg.toHide(address.phoneNumber || '')}}</text>
|
||||
</view>
|
||||
<view class="label-adds">
|
||||
<text class="adds address-info-class">
|
||||
<text wx:if="{{address.isDefault === 1}}" class="tag tag-default default-tag-class">默认</text>
|
||||
<text wx:if="{{address.tag}}" class="tag tag-primary normal-tag-class">{{address.tag}}</text>
|
||||
<text class="address-text">{{address.address}}</text>
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view catch:tap="onEdit" data-item="{{address}}" class="address-edit">
|
||||
<t-icon name="{{customIcon}}" class-prefix="{{classPrefix}}" size="46rpx" color="#BBBBBB" />
|
||||
</view>
|
||||
</view>
|
||||
<view slot="right" class="swipe-right-actions">
|
||||
<view wx:if="{{address.isDefault !== 1}}" class="swipe-action-btn set-default-btn" bindtap="onSetDefault" data-item="{{address}}">
|
||||
设为默认
|
||||
</view>
|
||||
<view class="swipe-action-btn delete-btn delete-class" bindtap="onDelete" data-item="{{address}}">
|
||||
删除
|
||||
</view>
|
||||
</view>
|
||||
</t-swipe-cell>
|
||||
</view>
|
||||
115
miniprogram/pages/user/components/ui-address-item/index.wxss
Normal file
115
miniprogram/pages/user/components/ui-address-item/index.wxss
Normal file
@@ -0,0 +1,115 @@
|
||||
.address-item-wrapper {
|
||||
overflow: hidden;
|
||||
}
|
||||
.address-item-wrapper .swipe-out .wr-swiper-cell {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
.address-item-wrapper .swipe-out .swipe-right-actions {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.address-item-wrapper .swipe-out .swipe-action-btn {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 144rpx;
|
||||
height: 100%;
|
||||
color: #fff;
|
||||
font-size: 28rpx;
|
||||
line-height: 40rpx;
|
||||
}
|
||||
|
||||
.address-item-wrapper .swipe-out .set-default-btn {
|
||||
background-color: #07c160;
|
||||
}
|
||||
|
||||
.address-item-wrapper .swipe-out .delete-btn {
|
||||
background-color: #fa4126;
|
||||
}
|
||||
.address-item-wrapper .draw-line {
|
||||
position: relative;
|
||||
}
|
||||
.address-item-wrapper .draw-line::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 32rpx;
|
||||
width: 200%;
|
||||
height: 2rpx;
|
||||
transform: scale(0.5);
|
||||
transform-origin: 0 0;
|
||||
box-sizing: border-box;
|
||||
border-bottom: #e5e5e5 2rpx solid;
|
||||
}
|
||||
.address-item-wrapper .address {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 32rpx;
|
||||
background-color: #fff;
|
||||
}
|
||||
.address-item-wrapper .address .address-edit {
|
||||
padding: 20rpx 0 20rpx 46rpx;
|
||||
}
|
||||
.address-item-wrapper .address .address-left {
|
||||
width: 80rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.address-item-wrapper .address .address-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .title {
|
||||
font-size: 32rpx;
|
||||
line-height: 48rpx;
|
||||
margin-bottom: 16rpx;
|
||||
color: #333333;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .title .text-style {
|
||||
margin-right: 8rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 280rpx;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .label-adds {
|
||||
display: flex;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .label-adds .adds {
|
||||
display: -webkit-box;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
color: #999999;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .label-adds .tag {
|
||||
display: inline-block;
|
||||
padding: 0rpx 8rpx;
|
||||
min-width: 40rpx;
|
||||
height: 32rpx;
|
||||
border-radius: 18rpx;
|
||||
font-size: 20rpx;
|
||||
line-height: 32rpx;
|
||||
text-align: center;
|
||||
margin-right: 8rpx;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .label-adds .tag-default {
|
||||
background: #ffece9;
|
||||
color: #fa4126;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .label-adds .tag-primary {
|
||||
background: #f0f1ff;
|
||||
color: #5a66ff;
|
||||
}
|
||||
.address-item-wrapper .address .address-content .label-adds .address-text {
|
||||
font-size: 28rpx;
|
||||
line-height: 40rpx;
|
||||
color: #999999;
|
||||
}
|
||||
Reference in New Issue
Block a user