首页 > 其他分享 >前端Vue自定义简单通用省市区选择器picker地区选择器picker 收获地址界面模版

前端Vue自定义简单通用省市区选择器picker地区选择器picker 收获地址界面模版

时间:2023-06-29 09:23:38浏览次数:54  
标签:picker function center 自定义 after tepData content front 选择器

前端Vue自定义简单通用省市区选择器picker地区选择器picker 收获地址界面模版,下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13266

效果图如下:

代码实现如下:

cc-selectDity

使用方法


<!-- 省市区选择 show:是否显示  @sureSelectArea:确认事件 @hideShow:隐藏事件-->

<cc-selectDity :show="show" @sureSelectArea="onsetCity" @hideShow="onhideShow"></cc-selectDity>

main.js文件设置全局函数

Vue.mixin({

methods: {

setData: function(obj, callback) {

let that = this;

const handleData = (tepData, tepKey, afterKey) => {

tepKey = tepKey.split('.');

tepKey.forEach(item => {

if (tepData[item] === null || tepData[item] === undefined) {

let reg = /^[0-9]+$/;

tepData[item] = reg.test(afterKey) ? [] : {};

tepData = tepData[item];

} else {

tepData = tepData[item];

}

});

return tepData;

};

const isFn = function(value) {

return typeof value == 'function' || false;

};

Object.keys(obj).forEach(function(key) {

let val = obj[key];

key = key.replace(/\]/g, '').replace(/\[/g, '.');

let front, after;

let index_after = key.lastIndexOf('.');

if (index_after != -1) {

after = key.slice(index_after + 1);

front = handleData(that, key.slice(0, index_after), after);

} else {

after = key;

front = that;

}

if (front.$data && front.$data[after] === undefined) {

Object.defineProperty(front, after, {

get() {

return front.$data[after];

},

set(newValue) {

front.$data[after] = newValue;

that.$forceUpdate();

},

enumerable: true,

configurable: true

});

front[after] = val;

} else {

that.$set(front, after, val);

}

});

isFn(callback) && this.$nextTick(callback);

}

}

});

HTML代码实现部分


<template>

<view>

<view class="editaddress">

<view class="content">

<view class="row">

<view class="nominal">收件人</view>

<view class="input"><input placeholder="请输入收件人姓名" v-model="addressData.name" type="text"></input>

</view>

</view>

<view class="row">

<view class="nominal">电话号码</view>

<view class="input"><input placeholder="请输入收件人电话号码" v-model="addressData.phone" type="number"

maxlength="11"></input></view>

</view>

<view class="row">

<view class="nominal">所在地区</view>

<view class="input selectcity" @tap="openPicker">

<input placeholder="请选择省市区" disabled type="text" v-model="addressData.address"></input>

<image src="/static/images/home/right.png" class="rights"></image>

</view>

</view>

<view class="row">

<view class="nominal">详细地址</view>

<view class="input"><textarea style="font-size: 28upx;" v-model="addressData.moreAddres"

auto-height="true" placeholder="输入详细地址" v-if="show == false"></textarea></view>

</view>

<view class="row">

<view class="nominal" style="color: #999;margin-top: 10upx;">设为默认地址</view>

<view class="input switch">

<switch :color="colors" style="transform:scale(0.8)" @change="switchChange"

:checked="addressData.isdefult == 1"></switch>

</view>

</view>

</view>

<view class="save">

<view class="btn" :style="'background:' + colors">保存地址</view>

</view>

<!-- 省市区选择 show:是否显示  @sureSelectArea:确认事件 @hideShow:隐藏事件-->

<cc-selectDity :show="show" @sureSelectArea="onsetCity" @hideShow="onhideShow"></cc-selectDity>

</view>

</view>

</template>

<script>

var app = getApp();

export default {

data() {

return {

colors: '',

show: false,

addressData: {

name: '',

phone: '',

address: '',

moreAddres: '',

isdefult: 0

},

isShow: true

};

},

components: {

},

props: {},

/**

* 生命周期函数--监听页面加载

*/

onLoad: function(options) {

},

/**

* 生命周期函数--监听页面初次渲染完成

*/

onReady: function() {},

/**

* 生命周期函数--监听页面显示

*/

onShow: function() {},

/**

* 生命周期函数--监听页面隐藏

*/

onHide: function() {},

/**

* 生命周期函数--监听页面卸载

*/

onUnload: function() {},

/**

* 页面相关事件处理函数--监听用户下拉动作

*/

onPullDownRefresh: function() {},

/**

* 页面上拉触底事件的处理函数

*/

onReachBottom: function() {},

/**

* 用户点击右上角分享

*/

onShareAppMessage: function() {},

methods: {

openPicker() {

console.log('执行')

this.show = true

},

onhideShow() {

this.show = false

console.log('执行了')

},

onsetCity(e) { //选中省市区

let data = e.detail.target.dataset;

let address = data.province + data.city + data.area;

this.show = false

this.addressData.address = address

},

switchChange(e) {

this.setData({

checked: e.detail.value

});

}

}

};

</script>

<style lang="scss" scoped>

.save {

position: fixed;

bottom: 0;

width: 100%;

height: 120upx;

display: flex;

justify-content: center;

align-items: center;

}

.save view {

display: flex;

}

.save .btn {

box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.4);

width: 70%;

height: 80upx;

border-radius: 80upx;

background-color: #f23a3a;

color: #fff;

justify-content: center;

align-items: center;

font-size: 30upx;

margin-bottom: 60px;

}

.save .btn .icon {

height: 80upx;

color: #fff;

font-size: 30upx;

justify-content: center;

align-items: center;

}

.content {

display: flex;

flex-wrap: wrap;

margin-top: 40upx;

}

.content view {

display: flex;

}

.content .row {

width: 92%;

margin: 0 4%;

border-bottom: solid 1upx #eee;

}

.content .row .nominal {

width: 30%;

height: 80upx;

font-size: 28upx;

font-family: Droid Sans Fallback;

font-weight: 400;

color: rgba(51, 51, 51, 1);

align-items: center;

}

.content .row .input {

width: 70%;

padding: 20upx 0;

align-items: center;

font-size: 28upx;

}

.content .row .input input {

font-size: 28upx;

color: #333333;

}

.content .row .switch {

justify-content: flex-end;

}

.content .row .input textarea {

min-height: 40upx;

line-height: 40upx;

}

.content .del_box {

width: 100%;

display: block;

overflow: hidden;

margin-right: 30upx;

}

.content .del {

width: 240upx;

height: 80upx;

float: right;

justify-content: center;

align-items: center;

font-size: 28upx;

color: #F23A3A;

margin: 0 auto;

margin-top: 50upx;

border-radius: 38upx;

background-color: rgba(255, 0, 0, 0.05);

border-bottom: solid 1upx #eee;

}

.selectcity input {

width: 90%;

}

.selectcity image {

width: 40upx;

height: 40upx;

float: right;

}

</style>

标签:picker,function,center,自定义,after,tepData,content,front,选择器
From: https://www.cnblogs.com/ccVue/p/17513129.html

相关文章

  • el-tree需要自定义双击事件触发选择节点
    单击事件onclick="xxxx"双击事件ondblclick="xxxx"<el-tree:data="data"@node-click="handleNodeClick"></el-tree>data(){return{numTime:0,}},methods:{//自定义双击事件handleNodeClick(......
  • 在vue文件中使用 deep深度选择器
    使用场景有的时候我们需要在父组件中去修改第三方组件或者子组件的样式就会使用到deep深度选择器。比如:App组件中定义了.title的样式,也想让Test子组件中的.title也应用对应的样式App.vue<template><divclass="app"><h1>app组件</h1><divclass="title">这是app......
  • 面向对象之魔术方法(内置方法),反射,异常之自定义异常
    魔术方法(内置方法)(面试题)#类里面内置的双下划线开头的一些方法,他们具有特殊的功能,我们称之为是魔术方法,简称魔法比如:__init__"""魔术方法的学习只需要掌握每个方法什么时候触发或者执行"""1.__str__,__repr__方法#__str__,__repr__方法classStudent():def_......
  • springboot 自定义异常 全局异常处理器
    创建自定义异常类,继承 RuntimeException类1publicclassCustomExceptionextendsRuntimeException{2publicCustomException(Stringmessage){3super(message);4}5}在指定情况下抛出该异常,代码如下: @ServicepublicclassCategoryServiceIm......
  • 完美,自定义View实现Dribbble上动感的Gallery App Icon 动画
    之前在dribbble看到一个很好看的动画效果,很想要,遂仿之。也为了练一下自定义控件,有段时间了,现在整理出来dribbble地址:https://dribbble.com/shots/4761564思路拆解一下,还是比较简单,需要绘制的有:圆形背景太阳(圆形)山(三角形)云朵(圆角矩形+三个圆)需要进行的动画:太阳-旋转动画山......
  • pyqt5:自定义信号实现/pyqt 打开网页/app.exec_()
    1、自定义信号  2、pyqt打开网页importwebbrowserwebbrowser.open('https://www.zhihu.com/question/23711222')3、app.exec_()与sys.exit(app.exec_())区别:app.exec_()#等待app主循环结束的,并在结束后执行后面行的程序#sys.exit(app.exec_())#起到等待主循环结束......
  • 前端Vue自定义手机号文本格式化组件手机号码文本转星号
    前端Vue自定义手机号文本格式化组件,下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13231效果图如下:cc-format-phone使用方法<!--phone:手机号isStar:是否转星号--><cc-format-phone:phone="":isStar="false"></cc-format-phone>......
  • 前端Vue自定义微信支付弹框dialog alert popup
    前端Vue自定义微信支付弹框dialogalertpopup, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13245效果图如下:实现代码如下:cc-payDialog使用方法<!--:money:支付金额 show:是否显示@cancel:取消 @success:确认支付--><cc-payDia......
  • SpringBoot自定义starter
    1、先来一个简单的案例非常简单的工程结构controllerpackagecom.ly.demo.controller;importcom.ly.demo.service.MyStarterService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.GetMapping;import......
  • 自定义代码片段
    前言使用自定义代码片段可以快速生成代码片段,提升开发效率。使用在vscode中ctrl+shift+p,新建全局代码片段。写好模板,复制进这个网站https://snippet-generator.app/将生成的模板复制进文件中......