Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
cff302a9
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6067
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
cff302a9
编写于
10月 23, 2024
作者:
shutao-dc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
还原
e5e9c009
合并时删除错误的文件
上级
de289d8e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
248 addition
and
0 deletion
+248
-0
uni_modules/native-time-picker/components/time-picker/time-picker.uvue
...ative-time-picker/components/time-picker/time-picker.uvue
+73
-0
uni_modules/native-time-picker/package.json
uni_modules/native-time-picker/package.json
+83
-0
uni_modules/native-time-picker/readme.md
uni_modules/native-time-picker/readme.md
+1
-0
uni_modules/native-time-picker/utssdk/app-android/config.json
...modules/native-time-picker/utssdk/app-android/config.json
+3
-0
uni_modules/native-time-picker/utssdk/app-ios/config.json
uni_modules/native-time-picker/utssdk/app-ios/config.json
+3
-0
uni_modules/native-time-picker/utssdk/app-ios/index.uts
uni_modules/native-time-picker/utssdk/app-ios/index.uts
+85
-0
未找到文件。
uni_modules/native-time-picker/components/time-picker/time-picker.uvue
0 → 100644
浏览文件 @
cff302a9
<template>
<view class="def-picker">
<native-view style="width: 100%; height: 100%;" @init="onviewinit" @timechanged="ontimechanged"></native-view>
</view>
</template>
<script lang="uts">
import { NativeTimePicker } from "@/uni_modules/native-time-picker";
export default {
data() {
return {
picker: null as NativeTimePicker | null,
hourValue: 0 as number,
minuteValue: 0 as number
}
},
props: {
"hour": {
type: Number,
default: 0
},
"minute": {
type: Number,
default: 0
}
},
watch: {
"hour": {
handler(newValue : number, oldValue : number) {
if (newValue < 23 && newValue >= 0) {
this.hourValue = newValue
this.picker?.setHour(this.hourValue)
}
},
immediate: true
},
"minute": {
handler(newValue : number, oldValue : number) {
if (newValue < 59 && newValue >= 0) {
this.minuteValue = newValue
this.picker?.setMinute(this.minuteValue)
}
},
immediate: true
},
},
methods: {
onviewinit(e : UniNativeViewInitEvent) {
this.picker = new NativeTimePicker(e.detail.element, this.hourValue, this.minuteValue);
this.$emit("load")
},
ontimechanged(e : UniNativeViewEvent) {
this.$emit("changed", e)
}
},
unmounted() {
}
}
</script>
<style>
.def-picker {
min-width: 300px;
min-height: 380px;
max-width: 400px;
max-height: 400px;
}
</style>
uni_modules/native-time-picker/package.json
0 → 100644
浏览文件 @
cff302a9
{
"id"
:
"uni-time-picker"
,
"displayName"
:
"uni-time-picker"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-time-picker"
,
"keywords"
:
[
"uni-time-picker"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.1.0"
},
"dcloudext"
:
{
"type"
:
"component-vue"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
,
"alipay"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-vue"
:
"u"
,
"app-nvue"
:
"u"
,
"app-uvue"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/native-time-picker/readme.md
0 → 100644
浏览文件 @
cff302a9
# uni-time-picker
\ No newline at end of file
uni_modules/native-time-picker/utssdk/app-android/config.json
0 → 100644
浏览文件 @
cff302a9
{
"minSdkVersion"
:
"21"
}
\ No newline at end of file
uni_modules/native-time-picker/utssdk/app-ios/config.json
0 → 100644
浏览文件 @
cff302a9
{
"deploymentTarget"
:
"12"
}
uni_modules/native-time-picker/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
cff302a9
import { UIDatePicker, UIControl, UIDatePickerStyle } from "UIKit"
import { DateFormatter } from "CoreFoundation"
export class NativeTimePicker {
element : UniNativeViewElement
timePicker : UIDatePicker
h : number
m : number
constructor(element : UniNativeViewElement, hour : number, minute : number) {
this.element = element
this.timePicker = new UIDatePicker()
this.h = hour
this.m = minute
super.init()
// 在 swift target-action 对应的方法需要以OC的方式来调用,那么OC语言中用Selector来表示一个方法的名称(又称方法选择器),创建一个Selector可以使用 Selector("functionName") 的方式。
const method = Selector("timeChange")
// 监听时间变化回调
this.timePicker.addTarget(this, action = method, for = UIControl.Event.valueChanged)
// 设置为时间选择模式
this.timePicker.datePickerMode = UIDatePicker.Mode.time
// 设置外观样式为 wheels
if (UTSiOS.available("iOS 13.4, *")) {
this.timePicker.preferredDatePickerStyle = UIDatePickerStyle.wheels
}
this.updateTime()
this.bindView(hour, minute)
}
// element 绑定原生view
bindView(hour : number, minute : number) {
this.element.bindIOSView(this.timePicker);
}
// 设置时
setHour(hour : number) {
this.h = hour
this.updateTime()
}
// 设置分
setMinute(minute : number) {
this.m = minute
this.updateTime()
}
// 更新显示
updateTime() {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
let date = formatter.date(from = `${this.h}:${this.m}`)
if (date != null) {
this.timePicker.date = date!
}
}
/**
* 按钮点击回调方法
* 在 swift 中,所有target-action (例如按钮的点击事件,NotificationCenter 的通知事件等)对应的 action 函数前面都要使用 @objc 进行标记。
*/
@objc timeChange() {
// 发送事件
console.log("timeChange")
let formatter = DateFormatter()
formatter.dateFormat = "HH"
let hourString = formatter.string(from = this.timePicker.date)
formatter.dateFormat = "mm"
let minuteString = formatter.string(from = this.timePicker.date)
const detail = { "hour": hourString, "minute": minuteString }
const event = new UniNativeViewEvent("timechanged", detail)
this.element.dispatchEvent(event)
}
destroy() {
UTSiOS.destroyInstance(this)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录