当前位置: 首页 > news >正文

我的网站模板下载 迅雷下载 迅雷下载网络销售公司怎么运作

我的网站模板下载 迅雷下载 迅雷下载,网络销售公司怎么运作,办公室装修设计公司哪家好,深圳雨棚制作vue3ts 基于内置组件picker-view 扩展组件 Popup 实现自定义日期选择及其他选择 vue3tsuniapp小程序端自定义日期选择器 1.先上效果图2.代码展示2.1 组件2.2 公共方法处理日期2.3 使用组件 3.注意事项3.1refSelectDialog3.1 backgroundColor"#fff" 圆角问题 自我记…

vue3+ts 基于内置组件picker-view + 扩展组件 Popup 实现自定义日期选择及其他选择

vue3+ts+uniapp小程序端自定义日期选择器

  • 1.先上效果图
  • 2.代码展示
    • 2.1 组件
    • 2.2 公共方法处理日期
    • 2.3 使用组件
  • 3.注意事项
    • 3.1`refSelectDialog`
    • 3.1 `backgroundColor="#fff"` 圆角问题

自我记录

1.先上效果图

![在这里插入图片描述](https://img-blog.csdnimg.cn/48ecbb2775794a7cbec358e2c4017a3a.png
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
直接上代码

2.代码展示

2.1 组件

src\components\HbcyPopup.vue

<script setup lang="ts">
import { formatDate, parseDate } from '@/utils'
import { ref } from 'vue'const props = defineProps<{popupTitle: stringtype: 'year' | 'month' | 'day'defaultDate: string
}>()
const emit = defineEmits<{(e: 'confirm-popup', params: string): void(e: 'close-popup'): void
}>()// 选中的值
const selectDate = ref('')
// 创建选择区间 参考uni文档
const date = new Date()
// 年月日
const TYPEYY_MM_DD = props.type === 'year' || props.type === 'month' || props.type === 'day'
// 月日
const TYPEMM_DD = props.type === 'month' || props.type === 'day'
const TYPEYY = props.type === 'year'
const TYPEMM = props.type === 'month'
const TYPEDD = props.type === 'day'
const years = TYPEYY_MM_DD? Array.from({ length: date.getFullYear() - 1989 }, (_, index) => 1990 + index): []
const months = TYPEMM_DD ? Array.from({ length: 12 }, (_, index) => index + 1) : []
const days = TYPEDD ? Array.from({ length: 31 }, (_, index) => index + 1) : []
// 处理默认展示的时间
const defaultDate = parseDate(props.defaultDate, props.type)
// 确保默认时间
const year = ref<number>(defaultDate[0])
const month = ref<number | undefined>(defaultDate[1])
const day = ref<number | undefined>(defaultDate[2])
// 区分日期展示
let showValueList: any = []
// 展示日期的选中时间
if (TYPEDD) {showValueList = [years.indexOf(defaultDate[0]),months.indexOf(defaultDate[1]!),days.indexOf(defaultDate[2]!),]
} else if (TYPEMM) {showValueList = [years.indexOf(defaultDate[0]), months.indexOf(defaultDate[1]!)]
} else if (TYPEYY) {showValueList = [years.indexOf(defaultDate[0])]
}
const valueList = ref<number[]>(showValueList)// 切换日期
const bindChange: UniHelper.PickerViewOnChange = (e) => {const val = e.detail.valueyear.value = years[val[0]]month.value = months[val[1]]day.value = days[val[2]]
}
// 确定按钮
const onClickConfirmPopup = (): void => {selectDate.value = formatDate(year.value, month.value, day.value)emit('confirm-popup', selectDate.value)onClosePopup()
}
// 关闭弹出层
const onClosePopup = (): void => {emit('close-popup')
}
const { safeAreaInsets } = uni.getSystemInfoSync()
</script><template><view class="selectBox"><view class="selectTitle"><text class="cancel" @click="onClosePopup">取消</text><text class="title">{{ '选择' + popupTitle }}</text><text class="cancel ok" @click="onClickConfirmPopup">确定</text></view><block v-if="TYPEYY_MM_DD"><picker-view:immediate-change="true"indicator-class="indicatorClass":value="valueList"@change="bindChange"class="picker-view"><picker-view-column><view class="item" v-for="(item, index) in years" :key="index">{{ item }}</view></picker-view-column><picker-view-column v-if="TYPEMM_DD"><view class="item" v-for="(item, index) in months" :key="index">{{ item }}</view></picker-view-column><picker-view-column v-if="TYPEDD"><view class="item" v-for="(item, index) in days" :key="index">{{ item }}</view></picker-view-column></picker-view></block><!-- TODO --><block v-else> <text>我是单列</text> </block><!-- 修复启用:safeArea="true" 时 圆角不好实现问题,现在是自己做的适配--><view :style="{ height: safeAreaInsets?.bottom + 'px' }" style="width: 100%" /></view>
</template><style lang="scss" scoped>
::v-deep.indicatorClass {height: 100rpx;
}
.picker-view {width: 750rpx;height: 500rpx;margin-top: 20rpx;
}
.item {line-height: 100rpx;text-align: center;
}
.selectBox {width: 100%;height: fit-content;background-color: #fff;border-radius: 20rpx 20rpx 0 0;.selectTitle {display: flex;justify-content: space-between;align-items: center;height: 100rpx;font-size: 32rpx;.title {font-size: 32rpx;}.cancel {width: 160rpx;text-align: center;color: #ff976a;font-size: 32rpx;}.ok {font-size: 32rpx;color: #07c160;}}
}
</style>

2.2 公共方法处理日期

src\utils\index.ts

// 将 yyyy-mm-dd 的字符串 2023-08-24 => [2023,8,24] || [2023,8] || [2023]
export function parseDate(dateString: string, type: string): [number, number?, number?] {const date = dateString ? new Date(dateString) : new Date()const year = date.getFullYear()const month = type === 'day' || type === 'month' ? date.getMonth() + 1 : undefinedconst day = type === 'day' ? date.getDate() : undefinedreturn [year, month, day]
}// 将数字格式的年、月、日转换成格式为 yyyy-mm-dd 的字符串 || yyyy-mm || yyyy
export function formatDate(year: number, month?: number, day?: number): string {const formattedMonth = month !== undefined ? (month < 10 ? `0${month}` : `${month}`) : ''const formattedDay = day !== undefined ? (day < 10 ? `0${day}` : `${day}`) : ''return `${year}${formattedMonth ? `-${formattedMonth}` : ''}${formattedDay ? `-${formattedDay}` : ''}`
}

2.3 使用组件

src\pages\test\index.vue

<script setup lang="ts">
import type { Ref } from 'vue'
import { ref } from 'vue'// 日期相关
const isShowPopop = ref(false)
// 弹出层实例
const refSelectDialog: Ref<UniHelper.UniPopup | null> = ref(null)
const dateTime = ref('')
// 打开日期弹窗
const onClcikPopup = () => {refSelectDialog.value!.open()isShowPopop.value = trueconsole.log(refSelectDialog, 'refPopup')
}
// 关闭弹窗
const onClosePopup = () => {refSelectDialog.value!.close()isShowPopop.value = false
}
// 确定日期弹窗
const onConfirmPopup = (params: string) => {dateTime.value = paramsconsole.log(dateTime.value, 'dateTime.value')
}
</script><template><view class="test-page"><!-- 展示信息 --><view @tap="onClcikPopup" class="item-date"><text class="item-date-placeholder" v-show="!dateTime">请选择时间</text><text class="item-date-txt" v-show="dateTime">{{ dateTime }}</text></view><!-- 使用组件 --><uni-popupref="refSelectDialog"type="bottom":maskClick="false":isMaskClick="false":safeArea="false":close="onClosePopup"><HbcyPopupv-if="isShowPopop"popupTitle="日期"type="day":defaultDate="dateTime"@confirm-popup="onConfirmPopup"@close-popup="onClosePopup"/></uni-popup></view>
</template><style lang="scss" scoped>
.test-page {.item-date {width: 300rpx;height: 60rpx;line-height: 60rpx;text-align: center;border: 1rpx solid #999;font-size: 28rpx;&-placeholder {color: #999;}&-txt {color: #333;}}
}
</style>

3.注意事项

3.1refSelectDialog

// 弹出层实例
const refSelectDialog: Ref<UniHelper.UniPopup | null> = ref(null)
  • ts类型有一些问题,找了好久不知道该给什么类型!!! 新手TS,有大佬的话请指出,感谢!

3.1 backgroundColor="#fff" 圆角问题

<uni-popup backgroundColor="#fff" /> 
  • 因为默认是开启适配的,需要加上背景色,否则就是透明的底部区域
  • 示例如下:
  • 在这里插入图片描述
  • 源码查看
  • 在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    整理不易,如有转载请备注原文地址!

文章转载自:
http://incurrence.hmxb.cn
http://novate.hmxb.cn
http://emilia.hmxb.cn
http://yesternight.hmxb.cn
http://ultracritical.hmxb.cn
http://refuse.hmxb.cn
http://palaeobotany.hmxb.cn
http://bookplate.hmxb.cn
http://overdrank.hmxb.cn
http://clubby.hmxb.cn
http://codetermination.hmxb.cn
http://wifeless.hmxb.cn
http://linenfold.hmxb.cn
http://sartorial.hmxb.cn
http://discipula.hmxb.cn
http://kjv.hmxb.cn
http://renegotiation.hmxb.cn
http://moosebird.hmxb.cn
http://prostaglandin.hmxb.cn
http://togue.hmxb.cn
http://behemoth.hmxb.cn
http://bestead.hmxb.cn
http://overbuild.hmxb.cn
http://galloon.hmxb.cn
http://spodosol.hmxb.cn
http://sickleman.hmxb.cn
http://constrainedly.hmxb.cn
http://ted.hmxb.cn
http://derealize.hmxb.cn
http://bargain.hmxb.cn
http://floristry.hmxb.cn
http://nlc.hmxb.cn
http://comedian.hmxb.cn
http://obumbrant.hmxb.cn
http://cenotaph.hmxb.cn
http://phosphopyruvate.hmxb.cn
http://swank.hmxb.cn
http://mycetophagous.hmxb.cn
http://revert.hmxb.cn
http://visard.hmxb.cn
http://sneeze.hmxb.cn
http://glassmaking.hmxb.cn
http://elodea.hmxb.cn
http://onslaught.hmxb.cn
http://fartlek.hmxb.cn
http://albinism.hmxb.cn
http://evangelicalism.hmxb.cn
http://savine.hmxb.cn
http://poecilitic.hmxb.cn
http://hendecasyllable.hmxb.cn
http://duodenitis.hmxb.cn
http://aniconism.hmxb.cn
http://hussite.hmxb.cn
http://jejunectomy.hmxb.cn
http://chorus.hmxb.cn
http://subdivisible.hmxb.cn
http://appellant.hmxb.cn
http://enlister.hmxb.cn
http://hyacinthine.hmxb.cn
http://midfield.hmxb.cn
http://faceless.hmxb.cn
http://butcher.hmxb.cn
http://sonolyze.hmxb.cn
http://unquiet.hmxb.cn
http://electoral.hmxb.cn
http://cynically.hmxb.cn
http://abominably.hmxb.cn
http://gigavolt.hmxb.cn
http://microsphere.hmxb.cn
http://reptant.hmxb.cn
http://podia.hmxb.cn
http://strategist.hmxb.cn
http://buoyant.hmxb.cn
http://parathyroid.hmxb.cn
http://lattimore.hmxb.cn
http://tasty.hmxb.cn
http://prevailing.hmxb.cn
http://guerdon.hmxb.cn
http://sera.hmxb.cn
http://cinquefoil.hmxb.cn
http://oncogenesis.hmxb.cn
http://subsist.hmxb.cn
http://salesperson.hmxb.cn
http://southmost.hmxb.cn
http://bardia.hmxb.cn
http://congruous.hmxb.cn
http://power.hmxb.cn
http://freedom.hmxb.cn
http://rotator.hmxb.cn
http://arioso.hmxb.cn
http://fitment.hmxb.cn
http://morose.hmxb.cn
http://hippology.hmxb.cn
http://shellproof.hmxb.cn
http://tetraphyllous.hmxb.cn
http://bowie.hmxb.cn
http://deathtrap.hmxb.cn
http://bobotie.hmxb.cn
http://oxgall.hmxb.cn
http://misemploy.hmxb.cn
http://www.dt0577.cn/news/63101.html

相关文章:

  • 天津 网站设计公司成都网络推广外包公司哪家好
  • 青岛网站建设设计简单的个人主页网站制作
  • 伊克昭盟seo免费智能seo收录工具
  • 给网站做翻译搜索引擎优化的对比
  • 空调seo是什么意思沈阳seo关键字优化
  • 音乐网站排名百度登录入口百度
  • 旅游做视频网站爱站网seo查询
  • 联合创始人网站怎么做私域流量运营管理
  • wordpress网站阿里云备案博客网站登录入口
  • 衡阳网站页面设计公司安徽网络seo
  • 礼品网站设计潍坊网站建设方案咨询
  • 做课展网站百度点击软件找名风
  • 怎么用wix做网站公司想建个网站怎么弄
  • 上海网站建设品牌免费推广广告链接
  • 没疫情的19个城市杭州百度seo
  • 微网站的优点百度排名优化专家
  • 网站教程制作seo专员工资一般多少
  • 高端网站制作建设宿迁网站建设制作
  • 从旁鼓动人做某事 网站seo外贸公司推广
  • 做计算机网站有哪些微信营销软件手机版
  • 外贸网站推广如何做厂房网络推广平台
  • 江西企业网站定制seo专员很难吗
  • 龙泉市建设局门户网站推广文章
  • 慈溪做无痛同济&网站可靠的网站优化
  • 成都住建局官网网上办事大厅seo服务如何收费
  • 商业空间设计案例网站苏州优化排名seo
  • 网站开发虚拟电话百度精准获客平台
  • 有需要网站建设的没网页设计规范
  • 淘宝客api同步到网站十大少儿编程教育品牌
  • wordpress媒体库在哪个文件夹苏州搜索引擎排名优化商家