### 0.3.8 专业版:

【优化】增加腾讯位置服务插件-微信小程序地图选点插件,替换以前的js调用腾讯地图选点插件。
This commit is contained in:
JianWeie
2022-05-06 16:04:26 +08:00
parent 424adecab1
commit 40b9cb8f39
4 changed files with 272 additions and 178 deletions

View File

@@ -78,6 +78,8 @@ const install = (Vue, vm) => {
let saveUserShipWx = (params, config = {}) => http.post('/Api/User/SaveUserShip', params, { custom: { methodName: 'user.saveusership', needToken: true } });
//获取区域ID
let getAreaId = (params, config = {}) => http.post('/Api/User/GetAreaId', params, { custom: { methodName: 'user.getareaid', needToken: false } });
//根据区/县名称获取城市id信息
let getAreaIdByName = (params, config = {}) => http.post('/Api/User/GetAreaIdByName', params, { custom: { methodName: 'user.getareaid', needToken: false } });
// 获取收货地址详情
let shipDetail = (params, config = {}) => http.post('/Api/User/GetShipDetail', params, { custom: { methodName: 'user.getshipdetail', needToken: true } });
// 收货地址编辑
@@ -439,6 +441,7 @@ const install = (Vue, vm) => {
saveUserShip,
saveUserShipWx,
getAreaId,
getAreaIdByName,
shipDetail,
editShip,
removeShip,

View File

@@ -110,9 +110,15 @@
"es6": true,
"checkSiteMap": false
},
"plugins": {
"chooseLocation": {
"version": "1.0.9",
"provider": "wx76a9a06e5b4e693e"
}
},
"permission": {
"scope.userLocation": {
"desc" : "用于获取您附近的门店列表"
"desc": "你的位置信息将用于小程序定位"
}
},
"optimization": {

View File

@@ -19,41 +19,32 @@
<u--input v-model="form.mobile" placeholder="请填写收货人手机号" />
</u-form-item>
<u-form-item label="选取区域" borderBottom>
<u-form-item label="省市县" borderBottom>
<coreshop-select v-model="show" mode="mutil-column-auto" :list="pickerList" :default-value="pickerIndex" @confirm="onConfirm"></coreshop-select>
<!-- 注意由于兼容性差异如果需要使用前后插槽nvue下需使用u--input非nvue下需使用u-input -->
<!-- #ifndef APP-NVUE -->
<u-input :value="pickerValue" type="select" disabled placeholder="请选择省市区区域">
<template slot="suffix">
<u-button text="选择" type="success" size="mini" @click="show = true"></u-button>
<u-button text="选择" type="success" size="mini" @click="toMap"></u-button>
</template>
</u-input>
<!-- #endif -->
<!-- #ifdef APP-NVUE -->
<u--input :value="pickerValue" type="select" disabled placeholder="请选择省市区区域">
<template slot="suffix">
<u-button text="选择" type="success" size="mini" @click="show = true"></u-button>
<u-button text="选择" type="success" size="mini" @click="toMap"></u-button>
</template>
</u--input>
<!-- #endif -->
</u-form-item>
<u-form-item label="选取街道" borderBottom>
<u-form-item label="地点" borderBottom>
<!-- 注意由于兼容性差异如果需要使用前后插槽nvue下需使用u--input非nvue下需使用u-input -->
<!-- #ifndef APP-NVUE -->
<u-input :value="form.street" type="text" disabled placeholder="请选择街道">
<template slot="suffix">
<u-button text="选择" type="success" size="mini" @click="toMap"></u-button>
</template>
</u-input>
<u-input :value="form.street" type="text" disabled placeholder="请选择"></u-input>
<!-- #endif -->
<!-- #ifdef APP-NVUE -->
<u--input :value="form.street" type="text" disabled placeholder="请选择街道">
<template slot="suffix">
<u-button text="选择" type="success" size="mini" @click="toMap"></u-button>
</template>
</u--input>
<u--input :value="form.street" type="text" disabled placeholder="请选择"></u--input>
<!-- #endif -->
</u-form-item>
@@ -83,6 +74,7 @@
</template>
<script>
const chooseLocation = requirePlugin('chooseLocation');
export default {
data() {
return {
@@ -96,6 +88,8 @@
latitude: '',
street: ''
},
longitude: 0,
latitude: 0,
region: ['湖南省', '怀化市', '鹤城区'],
areaId: 0,
checked: false,
@@ -152,7 +146,47 @@
},
}
},
onShow() {
const location = chooseLocation.getLocation(); // 如果点击确认选点按钮则返回选点结果对象否则返回null
if (location != null) {
this.form.latitude = location.latitude;
this.form.longitude = location.longitude;
this.region = [location.province, location.district, location.city];
//let data = {
// provinceName: location.province,
// cityName: location.district,
// countyName: location.city
//};
this.form.street = location.name;
this.form.address = location.address;
let postData = {
id: location.district
}
this.$u.api.getAreaIdByName(postData).then(res => {
if (res.status) {
this.areaId = res.data.areaId;
this.pickerValue = res.data.fullName;
} else {
uni.showModal({
title: '提示',
content: '地区选择出现问题,请重新选择地区',
showCancel: false
});
}
});
console.log("location1:", location);
}
},
onUnload() {
// 页面卸载时设置插件选点数据为null防止再次进入页面geLocation返回的是上次选点结果
chooseLocation.setLocation(null);
},
onLoad(e) {
this.getMyLocation();
if (e.shipId) {
//编辑
this.id = e.shipId;
@@ -168,6 +202,21 @@
this.$refs.uForm.setRules(this.rules);
},
methods: {
// 获取自己的位置信息
getMyLocation() {
let _this = this;
uni.getLocation({
type: 'wgs84',
success: function (res) {
_this.longitude = res.longitude;
_this.latitude = res.latitude;
},
fail: function () {
_this.$u.toast("获取位置信息失败")
}
});
},
onConfirm(e) {
let provinceName = e[0].label;
let cityName = e[1].label;
@@ -365,12 +414,24 @@
this.pickerIndex = [this.provinceKey, this.cityKey, this.areaKey];
},
toMap() {
if (!this.pickerValue) {
this.$u.toast('请先获取省市区信息');
return false;
} else {
this.$u.route('/pages/member/address/map/map', { pickerValue: this.pickerValue, areaId: this.areaId, longitude: this.form.longitude, latitude: this.form.latitude });
}
const txMapkey = this.$store.state.config.qqMapKey; //使用在腾讯位置服务申请的key
const referer = this.$store.state.config.shopName; //调用插件的app的名称
const location = JSON.stringify({
latitude: this.form.latitude == "" ? this.latitude : this.form.latitude,
longitude: this.form.longitude == "" ? this.longitude : this.form.longitude
});
const category = '';
wx.navigateTo({
url: 'plugin://chooseLocation/index?key=' + txMapkey + '&referer=' + referer + '&location=' +
location + '&category=' + category
});
//if (!this.pickerValue) {
// this.$u.toast('请先获取省市区信息');
// return false;
//} else {
// this.$u.route('/pages/member/address/map/map', { pickerValue: this.pickerValue, areaId: this.areaId, longitude: this.form.longitude, latitude: this.form.latitude });
//}
}
},

View File

@@ -561,6 +561,30 @@ namespace CoreCms.Net.Web.WebApi.Controllers
}
#endregion
#region /id信息
/// <summary>
/// 根据区/县名称获取城市id信息
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
public async Task<WebApiCallBack> GetAreaIdByName([FromBody] FMStringId entity)
{
var jm = new WebApiCallBack();
var dataArea = await _areaServices.QueryByClauseAsync(p => p.name == entity.id && p.depth == 3);
if (dataArea == null) return jm;
var fullName = await _areaServices.GetAreaFullName(dataArea.id);
jm.status = true;
jm.data = new
{
areaId = dataArea.id,
fullName = fullName.data
};
return jm;
}
#endregion
#region
/// <summary>
/// 注销登录