提交 61481937 编写于 作者: H hdx

unicloud-db-contacts: 简化变量命名, 更新 uni-loading 组件

上级 d619a122
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
const data = res.data const data = res.data
// const count = res.count // const count = res.count
this.mixinDatacomResData = data this.mixinDatacomResData = data
}).catch((err) => { }).catch((err: any | null) => {
this.mixinDatacomError = err as UniCloudError this.mixinDatacomError = err as UniCloudError
}).finally(() => { }).finally(() => {
this.mixinDatacomLoading = false this.mixinDatacomLoading = false
......
...@@ -40,18 +40,19 @@ ...@@ -40,18 +40,19 @@
return { return {
collection: COLLECTION_NAME, collection: COLLECTION_NAME,
genderList: GenderList as GenderType[], genderList: GenderList as GenderType[],
$uniCloudElement: null as UniCloudDBElement | null uniCloudElement: null as UniCloudDBElement | null
} }
}, },
onReady() { onReady() {
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
}, },
methods: { methods: {
onFormSubmit: function (e : FormSubmitEvent) { onFormSubmit: function (e : FormSubmitEvent) {
const formData = e.detail.value const formData = e.detail.value
const genderString = formData['gender'] as string const genderString = formData['gender'] as string
formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1 formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1
this.$uniCloudElement!.add(formData, { console.log('formData', formData)
this.uniCloudElement!.add(formData, {
showToast: false, showToast: false,
needLoading: true, needLoading: true,
loadingTitle: "正在保存...", loadingTitle: "正在保存...",
......
...@@ -39,14 +39,14 @@ ...@@ -39,14 +39,14 @@
return { return {
collection: '', collection: '',
where: '', where: '',
$whereID: '', whereID: '',
$uniCloudElement: null as UniCloudDBElement | null uniCloudElement: null as UniCloudDBElement | null
} }
}, },
onLoad(options : Map<string, string>) { onLoad(options) {
this.collection = COLLECTION_NAME; this.collection = COLLECTION_NAME;
this.$whereID = options.get('id') as string; this.whereID = options['id'] as string;
this.where = `_id=='${this.$whereID}'`; this.where = `_id=='${this.whereID}'`;
}, },
onShow() { onShow() {
// TODO 后续通过 EventChannel 实现 // TODO 后续通过 EventChannel 实现
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
uni.$off(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange); uni.$off(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange);
}, },
onReady() { onReady() {
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
}, },
methods: { methods: {
displayGender(value : number | null) : string { displayGender(value : number | null) : string {
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
}) })
}, },
onDataChange(_ : string) { onDataChange(_ : string) {
this.$uniCloudElement!.loadData() this.uniCloudElement!.loadData()
} }
} }
} }
......
...@@ -49,31 +49,31 @@ ...@@ -49,31 +49,31 @@
collection: '', collection: '',
where: '', where: '',
genderList: GenderList as GenderType[], genderList: GenderList as GenderType[],
$whereID: '', whereID: '',
$uniCloudElement: null as UniCloudDBElement | null uniCloudElement: null as UniCloudDBElement | null
} }
}, },
onLoad(options : Map<string, string>) { onLoad(options) {
this.collection = COLLECTION_NAME; this.collection = COLLECTION_NAME;
this.$whereID = options.get('id') as string; this.whereID = options['id'] as string;
this.where = `_id=='${this.$whereID}'`; this.where = `_id=='${this.whereID}'`;
}, },
onReady() { onReady() {
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
}, },
methods: { methods: {
onFormSubmit: function (e : FormSubmitEvent) { onFormSubmit: function (e : FormSubmitEvent) {
const formData = e.detail.value const formData = e.detail.value
const genderString = formData['gender'] as string const genderString = formData['gender'] as string
formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1 formData['gender'] = (genderString.length > 0) ? parseInt(genderString) : -1
this.$uniCloudElement!.update(this.$whereID, formData, { this.uniCloudElement!.update(this.whereID, formData, {
showToast: false, showToast: false,
needLoading: true, needLoading: true,
needConfirm: false, needConfirm: false,
loadingTitle: "正在保存...", loadingTitle: "正在保存...",
success: (_ : UniCloudDBUpdateResult) => { success: (_ : UniCloudDBUpdateResult) => {
// TODO 后续通过 EventChannel 实现 // TODO 后续通过 EventChannel 实现
uni.$emit(UNICLOUD_DB_CONTACTS_UPDATE, this.$whereID) uni.$emit(UNICLOUD_DB_CONTACTS_UPDATE, this.whereID)
setTimeout(() => { setTimeout(() => {
uni.navigateBack() uni.navigateBack()
}, 500) }, 500)
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
}) })
}, },
remove(id : string | null, name : string | null) { remove(id : string | null, name : string | null) {
this.$uniCloudElement!.remove(id!, { this.uniCloudElement!.remove(id!, {
needConfirm: true, needConfirm: true,
needLoading: true, needLoading: true,
loadingTitle: "正在删除...", loadingTitle: "正在删除...",
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
confirmContent: name, confirmContent: name,
success: (_ : UniCloudDBRemoveResult) => { success: (_ : UniCloudDBRemoveResult) => {
// TODO 后续通过 EventChannel 实现 // TODO 后续通过 EventChannel 实现
uni.$emit(UNICLOUD_DB_CONTACTS_DELETE, this.$whereID) uni.$emit(UNICLOUD_DB_CONTACTS_DELETE, this.whereID)
setTimeout(() => { setTimeout(() => {
uni.navigateBack({ uni.navigateBack({
delta: 2 delta: 2
......
...@@ -29,14 +29,14 @@ ...@@ -29,14 +29,14 @@
data() { data() {
return { return {
collection: COLLECTION_NAME, collection: COLLECTION_NAME,
$uniCloudElement: null as UniCloudDBElement | null uniCloudElement: null as UniCloudDBElement | null
} }
}, },
onReady() { onReady() {
// TODO 后续通过 EventChannel 实现 // TODO 后续通过 EventChannel 实现
uni.$on(UNICLOUD_DB_CONTACTS_DELETE, this.onDataChange); uni.$on(UNICLOUD_DB_CONTACTS_DELETE, this.onDataChange);
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.uniCloudElement = this.$refs['udb'] as UniCloudDBElement
this.$uniCloudElement!.loadData() this.uniCloudElement!.loadData()
}, },
onUnload() { onUnload() {
// TODO 后续通过 EventChannel 实现 // TODO 后续通过 EventChannel 实现
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
uni.$off(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange); uni.$off(UNICLOUD_DB_CONTACTS_UPDATE, this.onDataChange);
}, },
onPullDownRefresh() { onPullDownRefresh() {
this.$uniCloudElement!.loadData({ this.uniCloudElement!.loadData({
clear: true, clear: true,
success: (_ : UniCloudDBGetResult) => { success: (_ : UniCloudDBGetResult) => {
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
}, },
methods: { methods: {
loadMore() { loadMore() {
this.$uniCloudElement!.loadMore() this.uniCloudElement!.loadMore()
}, },
gotoAddPage() { gotoAddPage() {
// TODO 后续通过 EventChannel 实现 // TODO 后续通过 EventChannel 实现
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
}) })
}, },
onDataChange(_ : string) { onDataChange(_ : string) {
this.$uniCloudElement!.loadData({ this.uniCloudElement!.loadData({
clear: true clear: true
}) })
} }
...@@ -97,6 +97,11 @@ ...@@ -97,6 +97,11 @@
.udb { .udb {
flex: 1; flex: 1;
/* TODO */
/* #ifdef WEB */
display: flex;
/* #endif */
flex-direction: column;
} }
.list-view { .list-view {
......
## 1.0.4(2024-01-10)
- 优化 兼容 uvue h5 项目
## 1.0.3(2023-12-22)
- 更新 示例项目
## 1.0.2(2023-12-22)
- 优化 circle 部分动画逻辑,使动画更顺滑
## 1.0.1(2023-12-20) ## 1.0.1(2023-12-20)
- 修复 组件在高版本HBuilderX中运行出错的bug - 修复 组件在高版本HBuilderX中运行出错的bug
## 1.0.0(2023-12-19) ## 1.0.0(2023-12-19)
......
<template> <template>
<!-- #ifdef APP -->
<view :ref="elId" class="block" :style="{width:size+'px',height:size+'px'}"></view> <view :ref="elId" class="block" :style="{width:size+'px',height:size+'px'}"></view>
<!-- #endif -->
<!-- #ifdef WEB -->
<svg :width="size" :height="size" viewBox="25 25 50 50" :style="{width:size+'px',height:size+'px'}" class="uni-load__img uni-load__img--android-H5">
<circle cx="50" cy="50" r="20" fill="none" :style="{color:color}" :stroke-width="iconsSize"></circle>
</svg>
<!-- #endif -->
</template> </template>
<script> <script>
import { easeInOutCubic } from './util' import { easeInOutCubic } from './util'
let elId = 0
export default { export default {
name: "uni-loading", name: "circle",
props: { props: {
speed: { speed: {
type: Number, type: Number,
default: 16, default: 16,
...@@ -17,46 +24,66 @@ ...@@ -17,46 +24,66 @@
}, },
color: { color: {
type: String, type: String,
default: '', default: '#666',
} }
}, },
data() { data() {
const elId = `Uni_${(Math.random() * 10e5).toInt().toString(36)}` // 防止多调用,随机元素id
elId += 1
const elID = `Uni_Load_Circle_${elId}`
return { return {
elId: elId, elId: elID,
timer: 0, timer: 0,
}; };
}, },
computed: {
iconsSize() : number {
console.log(this.size / 10);
return (this.size / 10) +1
}
},
mounted() { mounted() {
// #ifdef APP
this.init() this.init()
// #endif
}, },
unmounted() { unmounted() {
// 组件卸载时,需要卸载定时器,优化性能,防止页面卡死
clearInterval(this.timer) clearInterval(this.timer)
}, },
methods: { methods: {
/**
* 初始化圆环
*/
init() { init() {
const refs = this.$refs[this.elId] as Element const refs = this.$refs[this.elId] as Element
let ctx = refs.getDrawableContext()! let ctx = refs.getDrawableContext()!
this.circular(ctx) this.build_circular(ctx)
}, },
circular(ctx : DrawableContext) {
/**
* 构建圆环动画
*/
build_circular(ctx : DrawableContext) {
let startAngle = 0; let startAngle = 0;
let rotate = 0; let rotate = 0;
const ARC_LENGTH = 359; const ARC_LENGTH = 359;
const center = this.size / 2; const center = this.size / 2; // 圆心
const lineWidth = this.size / 10; const lineWidth = this.size / 10; // 圆环宽度
const duration = 1200; // 动画持续时间 const duration = 1200; // 动画持续时间
const interval = this.speed; // 定时器间隔(大约 60 帧每秒) const interval = this.speed; // 定时器间隔(大约 60 帧每秒)
// 使圆环过度更自然,不必运动到底
const ARC_MAX = 358 const ARC_MAX = 358
let startTime = 0; let startTime = 0;
let foreward_end = 0 // 正传 let foreward_end = 0 // 正传
let reversal_end = ARC_MAX // 反转 let reversal_end = ARC_MAX // 反转
function pogress_time() : number { function pogress_time() : number {
const currentTime = Date.now(); const currentTime = Date.now();
// 运动时间计算
const elapsedTime = currentTime - startTime; const elapsedTime = currentTime - startTime;
const progress = elapsedTime / duration; const progress = elapsedTime / duration;
// 动画缓动
const easedProgress = easeInOutCubic(progress); const easedProgress = easeInOutCubic(progress);
return easedProgress return easedProgress
} }
...@@ -110,4 +137,51 @@ ...@@ -110,4 +137,51 @@
width: 50px; width: 50px;
height: 50px; height: 50px;
} }
/* #ifdef WEB */
.uni-load__img {
width: 24px;
height: 24px;
}
.uni-load__img--android-H5 {
animation: loading-android-H5-rotate 2s linear infinite;
transform-origin: center center;
}
.uni-load__img--android-H5 circle {
display: inline-block;
animation: loading-android-H5-dash 1.5s ease-in-out infinite;
stroke: currentColor;
stroke-linecap: round;
}
@keyframes loading-android-H5-rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@keyframes loading-android-H5-dash {
0% {
stroke-dasharray: 1, 200;
/* stroke-dashoffset: 0; */
}
50% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -20;
}
100% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -120;
}
}
/* #endif */
</style> </style>
<template> <template>
<uni-icons :id="elId" class='load-ani' :style="aniStyle" @transitionend="onEnd" :type="iconType" :size="size" :color="color"></uni-icons> <uni-icons :id="elId" class='load-ani' :style="aniStyle" @transitionend="onEnd" :type="iconType" :size="size" :color="color"></uni-icons>
<!-- return h(UniIcons, {
id: this.elId,
class: 'load-ani',
style: this.aniStyle,
onTransitionend: this.onEnd,
id: this.elId,
type: this.iconType,
color: this.color,
// TODO +2 是为了大小与自绘元素保持大小一致
size: this.loadWidth + 2,
}) -->
</template> </template>
<script> <script>
export default { export default {
name:'icon',
props: { props: {
iconType: { iconType: {
type: String, type: String,
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</template> </template>
<script> <script>
import Circle from './circle.uvue' import Circle from './circle.uvue'
// import Snow from './snow.uvue' // TODO 性能问题,其他类型暂时不对外开放
// import Icon from './icon.uvue' // import Icon from './icon.uvue'
// import UniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.uvue' // import UniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.uvue'
......
{ {
"id": "uni-loading", "id": "uni-loading",
"displayName": "uni-loading", "displayName": "uni-loading",
"version": "1.0.1", "version": "1.0.4",
"description": "加载动画组件多用在页面内数据加载时,提供一个loading动画,列表的上拉加载,下拉刷新等都需要加载动画", "description": "加载动画组件多用在页面内数据加载时,提供一个loading动画,列表的上拉加载,下拉刷新等都需要加载动画",
"keywords": [ "keywords": [
"loading", "loading",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册