新增定位和手机号组件

master
于肖磊 2025-07-01 17:03:16 +08:00
parent 7ec43b7021
commit 10d9bc1f21
14 changed files with 502 additions and 25 deletions

View File

@ -161,6 +161,8 @@
// key
cache_buy_user_address_select_key: 'cache_buy_user_address_select_key',
// key
cache_region_all_address_key: 'cache_region_all_address_key',
// key
cache_launch_info_key: 'cache_shop_launch_info_key',

View File

@ -853,8 +853,7 @@ export const get_format_checks_v2 = (common_config, value) => {
error_text = '';
} else {
is_error = '1';
const error_text = item.value == 'telephone-number' ? `请输入正确的电话号码或手机号码格式` : `请输入正确的${item.name}格式`;
error_text = error_text;
error_text = item.value == 'telephone-number' ? `请输入正确的电话号码或手机号码格式` : `请输入正确的${item.name}格式`;
}
} else {
// 如果值为空,重置错误状态
@ -973,12 +972,16 @@ export const time_stamp = (time, date_style = 'horizontal', date_type) => {
if (isEmpty(time)) {
return '';
}
let new_time = time.replace(/-/g, '/').replace(/年|月|日/g, '/').replace(/\/+$/, '');
let new_time = time;
// 检查时间是否符合日期格式, 不符合的话,添加上固定的年月日
if (['option1', 'option2'].includes(date_type) && isNaN(new Date(new_time).getTime())) {
new_time = '1970/01/01 ' + time.replace(/时|分|秒/g, ':').replace(/:+$/, '');
}
const date = new Date(new_time);
let date = new Date(new_time.replace(/-/g, '/').replace(/年|月|日/g, '/').replace(/\/+$/, ''));
// 如果可以直接解析成功,就使用直接解析好的数据
if (!isNaN(new Date(new_time).getTime())) {
date = new Date(new_time);
}
// 获取各时间组件
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');

View File

@ -0,0 +1,127 @@
<template>
<view class="flex-col gap-10">
<view class="flex-row align-c" :style="com_data.common_style + propStyle" @tap="open_ragion">
<text v-if="province_name" class="flex-1">{{ province_name }}{{ city_name ? ' / ' + city_name : '' }}{{ county_name ? ' / ' + county_name : '' }}</text>
<text v-else class="placeholder flex-1">{{ placeholder }}</text>
<template v-if="propDirection == 'row'">
<iconfont name="icon-arrow-right" size="24rpx" color="#666" propContainerDisplay="flex"></iconfont>
</template>
<template v-else>
<iconfont name="icon-arrow-bottom" size="24rpx" color="#666" propContainerDisplay="flex" ></iconfont>
</template>
</view>
<view v-if="address_type == 'detailed'" class="flex-row">
<textarea :value="detailed_value" class="uni-input flex-1 ht-auto" :style="com_data.common_style + propStyle + 'padding: 18rpx 22rpx;min-height:100rpx;'" placeholder="请输入详细地址" @input="input_value_event" />
</view>
</view>
</template>
<script>
import { get_format_checks, isEmpty, formatNumber } from '@/common/js/common/common.js';
const app = getApp();
export default {
props: {
propValue: {
type: Object,
default: () => ({}),
},
propKey: {
type: [String, Number],
default: 0,
},
propDataIndex: {
type: Number,
default: 0,
},
propStyle: {
type: String,
default: '',
},
propDirection: {
type: String,
default: 'row',
}
},
data() {
return {
placeholder: '请选择内容...',
address_type: '',
form_value: '',
detailed_value: '',
com_data: {},
region_picker_show: false,
province_id: '',
city_id: '',
county_id: '',
province_name: '',
city_name: '',
county_name: '',
};
},
watch: {
propValue(val) {
this.init();
},
propKey(val) {
//
this.init();
},
},
mounted() {
this.init();
},
methods: {
isEmpty,
init() {
const com_data = this.propValue;
this.setData({
com_data: com_data,
address_type: com_data.address_type || 'noDetailed',
placeholder: com_data?.placeholder || '请选择内容...',
form_value: com_data?.form_value || '',
detailed_value: com_data?.detailed_value || '',
province_id: com_data?.form_value[0] || '',
city_id: com_data?.form_value[1] || '',
county_id: com_data?.form_value[2] || '',
province_name: com_data.province_name || '',
city_name: com_data.city_name || '',
county_name: com_data.county_name || '',
});
},
focus_input(e) {
let value = '';
//
if (!isEmpty(e.detail.value)) {
value = Number(formatNumber(e.detail.value, false)).toFixed(this.decimal_num);
}
this.setData({
form_value: value,
});
},
open_ragion() {
this.$emit('openRagion', this.propDataIndex, this.province_id, this.city_id, this.county_id);
},
data_check(val) {
const { is_error = '0', error_text = '' } = get_format_checks(this.com_data, val, true, 'number');
this.$emit('dataCheck', { is_error, error_text, value: val, index: this.propDataIndex });
},
input_value_event(e) {
//
this.setData({
detailed_value: e.detail.value,
});
this.$emit('dataAddressChange', { value: e.detail.value, index: this.propDataIndex });
}
}
}
</script>
<style lang="scss" scoped>
.number-icon {
color: #ccc;
}
.placeholder {
color: #606266;
opacity: 0.6;
}
</style>

View File

@ -27,7 +27,6 @@
import { get_format_checks, isEmpty, get_color_style, get_math, color_change } from '@/common/js/common/common.js';
const app = getApp();
export default {
name: 'diy',
props: {
propValue: {
type: Object,

View File

@ -33,7 +33,6 @@
import { get_format_checks, isEmpty, time_stamp } from '@/common/js/common/common.js';
import myDatetime from '@/pages/form-input/components/form-input/modules/my-datetime/my-datetime.vue';
export default {
name: 'diy',
components: {
myDatetime
},

View File

@ -27,7 +27,6 @@
import { get_format_checks, isEmpty, time_stamp } from '@/common/js/common/common.js';
import myDatetime from '@/pages/form-input/components/form-input/modules/my-datetime/my-datetime.vue';
export default {
name: 'diy',
components: {
myDatetime
},

View File

@ -19,33 +19,39 @@
</view>
</view>
<view class="flex-1 wh-auto flex-col gap-5">
<view v-if="['single-text', 'radio-btns', 'select'].includes(item.key) && item.com_data.type == 'single-text'" class="wh-auto" :style="item.com_data.common_style">
<view v-if="['single-text', 'radio-btns', 'select'].includes(item.key) && item.com_data.type == 'single-text'" :style="item.com_data.common_style">
<componentInput :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentInput>
</view>
<view v-else-if="item.key == 'multi-text'" class="wh-auto" :style="item.com_data.common_style + 'padding: 18rpx 8rpx;'">
<view v-else-if="item.key == 'multi-text'" :style="item.com_data.common_style + 'padding: 18rpx 22rpx;'">
<componentTextarea :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentTextarea>
</view>
<view v-else-if="['select-multi', 'checkbox'].includes(item.key) && item.com_data.type == 'checkbox'" class="wh-auto">
<view v-else-if="['select-multi', 'checkbox'].includes(item.key) && item.com_data.type == 'checkbox'">
<componentCheckbox :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change" @data_option_change="data_option_change"></componentCheckbox>
</view>
<view v-else-if="['single-text', 'radio-btns', 'select'].includes(item.key) && item.com_data.type == 'radio-btns'" class="wh-auto">
<view v-else-if="['single-text', 'radio-btns', 'select'].includes(item.key) && item.com_data.type == 'radio-btns'">
<componentRadio :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentRadio>
</view>
<view v-else-if="['single-text', 'radio-btns', 'select'].includes(item.key) && item.com_data.type == 'select'" class="wh-auto" :style="item.com_data.common_style">
<view v-else-if="['single-text', 'radio-btns', 'select'].includes(item.key) && item.com_data.type == 'select'" :style="item.com_data.common_style">
<componentSelect :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propDirection="flex_direction" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentSelect>
</view>
<view v-else-if="['select-multi', 'checkbox'].includes(item.key) && item.com_data.type == 'select-multi'" class="wh-auto" :style="item.com_data.common_style">
<view v-else-if="['select-multi', 'checkbox'].includes(item.key) && item.com_data.type == 'select-multi'" :style="item.com_data.common_style">
<componentSelectMulti :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propDirection="flex_direction" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change" @data_option_change="data_option_change"></componentSelectMulti>
</view>
<view v-else-if="item.key == 'number'" class="wh-auto" :style="item.com_data.common_style">
<view v-else-if="item.key == 'number'" :style="item.com_data.common_style">
<componentNumber :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentNumber>
</view>
<view v-else-if="item.key == 'date'" class="wh-auto" :style="item.com_data.common_style">
<view v-else-if="item.key == 'date'" :style="item.com_data.common_style">
<componentDate :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentDate>
</view>
<view v-else-if="item.key == 'date-group'" class="wh-auto" :style="item.com_data.common_style">
<view v-else-if="item.key == 'date-group'" :style="item.com_data.common_style">
<componentDateGroup :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" @dataCheck="data_check" @dataChange="data_change"></componentDateGroup>
</view>
<view v-else-if="item.key == 'address'">
<componentAddress :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" :propDirection="flex_direction" @dataCheck="data_check" @dataChange="data_change" @openRagion="open_ragion" @dataAddressChange="dataAddressChange"></componentAddress>
</view>
<view v-else-if="item.key == 'phone'">
<componentPhone :propValue="item.com_data" :propKey="propKey" :propDataIndex="index" :propMobile="mobile" :propStyle="component_style" :propDirection="flex_direction" @dataCheck="data_check" @dataChange="data_change" @dataCodeCheck="data_code_check" @dataCodeChage="data_code_chage"></componentPhone>
</view>
<view v-if="!isEmpty(item.com_data.common_config.error_text)" class="field-invalid-info">{{ item.com_data.common_config.error_text }}</view>
</view>
</view>
@ -67,6 +73,7 @@
<uni-popup ref="popup" type="center" border-radius="20rpx">
<view class="popup-content">{{ popup_help_content }}</view>
</uni-popup>
<component-region-picker :propProvinceId="province_id" :propCityId="city_id" :propCountyId="county_id" :propShow="region_picker_show" @onclose="close_event" @callBackEvent="region_event"></component-region-picker>
</view>
</view>
</template>
@ -82,9 +89,12 @@ import componentSelect from '@/pages/form-input/components/form-input/select.vue
import componentNumber from '@/pages/form-input/components/form-input/number.vue';
import componentDate from '@/pages/form-input/components/form-input/date.vue';
import componentDateGroup from '@/pages/form-input/components/form-input/date-group.vue';
import componentAddress from '@/pages/form-input/components/form-input/address.vue';
import componentSelectMulti from '@/pages/form-input/components/form-input/select-multi.vue';
import componentPhone from '@/pages/form-input/components/form-input/phone.vue';
import componentRegionPicker from '@/pages/common/components/region-picker/region-picker';
export default {
name: 'diy',
name: 'formInput',
components: {
componentInput,
componentTextarea,
@ -95,6 +105,9 @@ export default {
componentSelectMulti,
componentDate,
componentDateGroup,
componentAddress,
componentRegionPicker,
componentPhone,
},
props: {
propValue: {
@ -128,6 +141,12 @@ export default {
submit_bg_color: '',
bottom_fixed_style: '',
popup_help_content: '',
//
address_index: 0,
province_id: '',
city_id: '',
county_id: '',
region_picker_show: false,
};
},
watch: {
@ -141,7 +160,6 @@ export default {
},
methods: {
isEmpty,
init() {
const data = this.propValue;
//
@ -169,7 +187,7 @@ export default {
});
},
get_form_border_style(item, flex_direction) {
return flex_direction == 'row' ? '' : common_form_styles_computer(item) + 'padding: 0px 8rpx;';
return flex_direction == 'row' ? '' : common_form_styles_computer(item) + 'padding: 0px 22rpx;box-sizing:content-box;';
},
data_check(e) {
const { is_error, error_text, value, index } = e;
@ -179,12 +197,26 @@ export default {
data[index].com_data.common_config.error_text = error_text;
this.setData({ data_list: data });
},
data_code_check(e) {
const { is_error, error_text, value, index } = e;
const data = this.data_list;
data[index].com_data.form_value_code = value;
data[index].com_data.common_config.is_error = is_error;
data[index].com_data.common_config.error_text = error_text;
this.setData({ data_list: data });
},
data_change(e) {
const { value, index } = e;
const data = this.data_list;
data[index].com_data.form_value = value;
this.setData({ data_list: data });
},
data_code_chage(e) {
const { value, index } = e;
const data = this.data_list;
data[index].com_data.form_value_code = value;
this.setData({ data_list: data });
},
data_option_change(e) {
const { list, value, index } = e;
const data = this.data_list;
@ -192,9 +224,50 @@ export default {
data[index].com_data.custom_option_list = list;
this.setData({ data_list: data });
},
dataAddressChange(e) {
const { value, index } = e;
const data = this.data_list;
data[index].com_data.detailed_value = value;
this.setData({ data_list: data });
},
help_icon_event(e) {
this.setData({ popup_help_content: e.currentTarget.dataset.value });
this.$refs.popup.open();
},
open_ragion(index, province_id, city_id, county_id) {
this.setData({
region_picker_show: true,
province_id,
city_id,
county_id,
address_index: index,
});
},
close_event(e) {
this.setData({
region_picker_show: false
});
},
region_event(e) {
let data = uni.getStorageSync(app.globalData.data.cache_region_picker_choice_key) || {};
if((data.province || null) == null) {
data.province = {};
}
if((data.city || null) == null) {
data.city = {};
}
if((data.areal || null) == null) {
data.areal = {};
}
const list = this.data_list;
list[this.address_index].com_data = {
...list[this.address_index].com_data,
form_value: [data.province.id, data.city.id, data.areal.id],
province_name: data.province.name || '',
city_name: data.city.name || '',
county_name: data.areal.name || '',
}
}
}
}

View File

@ -8,7 +8,6 @@
<script>
import { get_format_checks, isEmpty } from '@/common/js/common/common.js';
export default {
name: 'diy',
props: {
propValue: {
type: Object,

View File

@ -14,7 +14,6 @@
import { get_format_checks, isEmpty, formatNumber } from '@/common/js/common/common.js';
const app = getApp();
export default {
name: 'diy',
props: {
propValue: {
type: Object,

View File

@ -0,0 +1,281 @@
<template>
<view class="flex-col gap-10">
<view class="flex-row align-c gap-5" :style="com_data.common_style + propStyle">
<iconfont name="icon-phone" size="24rpx" color="#666" propContainerDisplay="flex" ></iconfont>
<input :value="form_value" class="uni-input flex-1" :style="propStyle" type="text" :placeholder="placeholder" @blur="data_check" @input="input_value_event" />
</view>
<view v-if="com_data.is_sms_verification == '1'" class="flex-row gap-10">
<input :value="form_value_code" class="uni-input flex-1" :style="com_data.common_style + propStyle" type="text" placeholder="请输入手机验证码" @blur="data_code_check" @input="input_code_value_event" />
<button :class="'uni-button flex-row align-c' + ( verify_submit_disabled ? 'verify_disabled' : '')" :style="propStyle + 'height:auto;'" type="default" :disabled="verify_submit_disabled" @click="verify_send_event">{{ verify_submit_text }}</button>
</view>
<!-- 图片验证码弹层 -->
<component-popup :propShow="popup_image_verify_status" propPosition="bottom" @onclose="popup_image_verify_close_event">
<view class="bg-white padding-horizontal-main padding-top-main">
<view class="fr oh">
<view class="fr" @tap.stop="popup_image_verify_close_event">
<iconfont name="icon-close-o" size="28rpx" color="#999"></iconfont>
</view>
</view>
<view class="form-content margin-top-xxxl padding-top-xxl">
<view class="verify pr margin-vertical-main">
<input type="text" :placeholder="$t('login.login.t3951j')" name="verify" maxlength="4" :value="form_input_image_verify_value" @input="form_input_image_verify_event" />
<image v-if="(verify_image_url || null) != null" :src="verify_image_url" class="verify-image pa" mode="aspectFit" data-type="sms" @tap="image_verify_event"></image>
</view>
<view class="margin-top-xxxl margin-bottom-xxxl">
<button :class="'bg-main br-main cr-white round text-size' + ( verify_disabled ? ' verify_disabled' : '')" type="default" @tap="popup_image_verify_submit_event" hover-class="none" :disabled="verify_disabled">{{ $t('common.confirm') }}</button>
</view>
</view>
</view>
</component-popup>
</view>
</template>
<script>
import { get_format_checks, isEmpty } from '@/common/js/common/common.js';
import componentPopup from '@/components/popup/popup';
const app = getApp();
export default {
components: {
componentPopup,
},
props: {
propValue: {
type: Object,
default: () => ({}),
},
propKey: {
type: [String, Number],
default: 0,
},
propDataIndex: {
type: Number,
default: 0,
},
propStyle: {
type: String,
default: '',
}
},
data() {
return {
placeholder: '请输入内容...',
form_value: '',
form_value_code: '',
com_data: {},
decimal_num: 0,
is_thousandths_symbol: '0',
format: '',
popup_image_verify_status: false,
form_input_image_verify_value: '',
verify_image_url: '',
verify_disabled: false,
verify_submit_disabled: false,
verify_time_total: 60,
temp_clear_time: null,
};
},
watch: {
propKey(val) {
//
this.init();
},
},
mounted() {
this.init();
},
methods: {
isEmpty,
init() {
const com_data = this.propValue;
if (com_data.is_img_sms_verification == '1') {
this.image_verify_event('sms');
}
this.setData({
com_data: com_data,
placeholder: com_data?.placeholder || '请输入内容...',
form_value: com_data?.form_value || '',
form_value_code: com_data?.form_value_code || '',
format: com_data.format,
verify_submit_text: this.$t('login.login.s665h5'),
verify_submit_disabled: true,
});
},
data_check() {
const data = this.com_data;
if (data) {
data.common_config.format = data.is_telephone === '1' ? 'telephone-number' : 'phone-number';
}
const { is_error = '0', error_text = '' } = get_format_checks(data, this.form_value, true);
this.$emit('dataCheck', { is_error, error_text, value: this.form_value, index: this.propDataIndex });
},
data_code_check() {
let is_error = '0';
let error_text = '';
if (this.com_data.is_required == '1' && isEmpty(this.form_value_code)) {
//
is_error = '1';
error_text = '短信验证码不能为空';
}
this.$emit('dataCodeCheck', { is_error, error_text, value: this.form_value_code, index: this.propDataIndex });
},
verify_send_event() {
if (this.com_data.is_img_sms_verification == '1') {
this.setData({
form_input_image_verify_value: '',
popup_image_verify_status: true,
verify_disabled: true,
});
} else {
this.verify_send_handle();
}
},
//
image_verify_event(e) {
var type = typeof e == 'string' ? e : e.currentTarget.dataset.type || null;
if (type !== null) {
var tv = app.globalData.get_timestamp();
var url = app.globalData.get_request_url('userverifyentry', 'user', '', 'type=' + type + '&t=' + tv);
this.setData({
verify_image_url: url,
});
}
},
//
form_input_image_verify_event(e) {
if (e.detail.value.length == 4) {
this.setData({
verify_disabled: false,
});
} else {
this.setData({
verify_disabled: true,
});
}
this.setData({
form_input_image_verify_value: e.detail.value,
});
},
//
popup_image_verify_close_event(e) {
this.setData({
popup_image_verify_status: false,
});
},
popup_image_verify_submit_event() {
this.verify_send_handle();
},
verify_send_handle() {
const post_data = {
accounts: this.form_value,
type: 'sms',
verify:this.com_data.is_img_sms_verification == '1' ? this.form_input_image_verify_value : ''
}
let self = this;
uni.request({
url: app.globalData.get_request_url('regverifysend', 'user'),
method: 'POST',
data: post_data,
dataType: 'json',
success: (res) => {
uni.hideLoading();
if (res.data.code == 0) {
//
if (this.com_data.is_img_sms_verification == '1') {
this.setData({
popup_image_verify_status: false,
});
}
//
var temp_time = this.verify_time_total;
this.temp_clear_time = setInterval(function () {
if (temp_time <= 1) {
clearInterval(self.temp_clear_time);
self.setData({
verify_submit_text: self.$t('login.login.s665h5'),
verify_disabled: false,
});
} else {
temp_time--;
self.setData({
verify_submit_text: self.$t('login.login.n24i5u') + temp_time + self.$t('login.login.4306xr'),
});
}
}, 1000);
} else {
this.setData({
verify_submit_text: this.$t('login.login.s665h5'),
verify_disabled: false,
form_input_image_verify_value: '',
});
this.image_verify_event('sms');
app.globalData.showToast(res.data.msg);
}
},
fail: () => {
uni.hideLoading();
this.setData({
verify_submit_text: this.$t('login.login.s665h5'),
verify_disabled: false,
form_input_image_verify_value: '',
});
this.image_verify_event('sms');
app.globalData.showToast(this.$t('common.internet_error_tips'));
},
});
},
input_value_event(e) {
//
this.setData({
form_value: e.detail.value,
verify_submit_disabled: !isEmpty(e.detail.value) ? false : true,
});
this.$emit('dataChange', { value: e.detail.value, index: this.propDataIndex });
},
input_code_value_event(e) {
//
this.setData({
form_value_code: e.detail.value,
});
this.$emit('dataCodeChange', { value: e.detail.value, index: this.propDataIndex });
}
}
}
</script>
<style lang="scss" scoped>
.number-icon {
color: #ccc;
}
.uni-button {
display: flex;
align-items: center;
justify-content: center;
min-width: 200rpx;
border: 2rpx solid #ccc;
}
.verify_disabled {
opacity: 0.6;
}
.form-content .verify input {
width: 63%;
height: 50px;
line-height: 50px;
padding: 0 36rpx;
box-sizing: border-box;
}
.form-content .verify {
height: 50px;
line-height: 50px;
background: #F9F9F9;
border-radius: 25px;
border: 0;
}
.form-content .verify .verify-image {
width: 35%;
height: 50px;
line-height: 50px;
top: 0;
right: 36rpx;
}
</style>

View File

@ -12,7 +12,6 @@
import { get_format_checks, isEmpty, get_color_style } from '@/common/js/common/common.js';
const app = getApp();
export default {
name: 'diy',
props: {
propValue: {
type: Object,

View File

@ -75,7 +75,6 @@
import { get_format_checks, isEmpty, get_color_style, color_change } from '@/common/js/common/common.js';
import componentPopup from '@/components/popup/popup';
export default {
name: 'diy',
components: {
componentPopup,
},

View File

@ -55,7 +55,6 @@
import { get_format_checks, isEmpty, get_color_style } from '@/common/js/common/common.js';
import componentPopup from '@/components/popup/popup';
export default {
name: 'diy',
components: {
componentPopup,
},

View File

@ -9,7 +9,6 @@
import { get_format_checks, isEmpty } from '@/common/js/common/common.js';
const app = getApp();
export default {
name: 'diy',
props: {
propValue: {
type: Object,