提交 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>
<view :ref="elId" class="block" :style="{width:size+'px',height:size+'px'}"></view> <!-- #ifdef APP -->
<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'
export default { let elId = 0
name: "uni-loading", export default {
props: { name: "circle",
props: {
speed: { speed: {
type: Number, type: Number,
default: 16, default: 16,
}, },
size: { size: {
type: Number, type: Number,
default: 20, default: 20,
}, },
color: { color: {
type: String, type: String,
default: '', default: '#666',
} }
}, },
data() { data() {
const elId = `Uni_${(Math.random() * 10e5).toInt().toString(36)}` // 防止多调用,随机元素id
return { elId += 1
elId: elId, const elID = `Uni_Load_Circle_${elId}`
timer: 0, return {
}; elId: elID,
}, timer: 0,
mounted() { };
this.init() },
}, computed: {
unmounted() { iconsSize() : number {
clearInterval(this.timer) console.log(this.size / 10);
}, return (this.size / 10) +1
methods: { }
init() { },
const refs = this.$refs[this.elId] as Element mounted() {
let ctx = refs.getDrawableContext()! // #ifdef APP
this.circular(ctx) this.init()
}, // #endif
circular(ctx : DrawableContext) { },
let startAngle = 0; unmounted() {
let rotate = 0; // 组件卸载时,需要卸载定时器,优化性能,防止页面卡死
const ARC_LENGTH = 359; clearInterval(this.timer)
const center = this.size / 2; },
const lineWidth = this.size / 10; methods: {
const duration = 1200; // 动画持续时间 /**
const interval = this.speed; // 定时器间隔(大约 60 帧每秒) * 初始化圆环
*/
init() {
const ARC_MAX = 358 const refs = this.$refs[this.elId] as Element
let startTime = 0; let ctx = refs.getDrawableContext()!
let foreward_end = 0 // 正传 this.build_circular(ctx)
let reversal_end = ARC_MAX // 反转 },
function pogress_time() : number {
const currentTime = Date.now(); /**
const elapsedTime = currentTime - startTime; * 构建圆环动画
const progress = elapsedTime / duration; */
const easedProgress = easeInOutCubic(progress); build_circular(ctx : DrawableContext) {
return easedProgress let startAngle = 0;
} let rotate = 0;
const draw = () => { const ARC_LENGTH = 359;
const center = this.size / 2; // 圆心
ctx.reset(); const lineWidth = this.size / 10; // 圆环宽度
ctx.beginPath(); const duration = 1200; // 动画持续时间
const interval = this.speed; // 定时器间隔(大约 60 帧每秒)
if (reversal_end == ARC_MAX) {
foreward_end = Math.min(pogress_time() * ARC_LENGTH, ARC_LENGTH); // 限制 end 的最大值为 ARC_LENGTH // 使圆环过度更自然,不必运动到底
if (foreward_end >= ARC_MAX) { const ARC_MAX = 358
reversal_end = 0 let startTime = 0;
foreward_end = ARC_MAX let foreward_end = 0 // 正传
startTime = Date.now(); let reversal_end = ARC_MAX // 反转
} function pogress_time() : number {
} const currentTime = Date.now();
// 运动时间计算
if (foreward_end == ARC_MAX) { const elapsedTime = currentTime - startTime;
reversal_end = Math.min(pogress_time() * ARC_LENGTH, ARC_LENGTH); const progress = elapsedTime / duration;
if (reversal_end >= ARC_MAX) { // 动画缓动
reversal_end = ARC_MAX const easedProgress = easeInOutCubic(progress);
foreward_end = 0 return easedProgress
startTime = Date.now(); }
} const draw = () => {
}
ctx.reset();
ctx.arc( ctx.beginPath();
center,
center, if (reversal_end == ARC_MAX) {
center - lineWidth, foreward_end = Math.min(pogress_time() * ARC_LENGTH, ARC_LENGTH); // 限制 end 的最大值为 ARC_LENGTH
startAngle + rotate + (reversal_end * Math.PI / 180), if (foreward_end >= ARC_MAX) {
startAngle + rotate + (foreward_end * Math.PI / 180) reversal_end = 0
); foreward_end = ARC_MAX
ctx.lineWidth = lineWidth; startTime = Date.now();
const fillColor = (this.color !== '' ? this.color : '#666').toString(); }
ctx.strokeStyle = fillColor; }
ctx.stroke();
ctx.update(); if (foreward_end == ARC_MAX) {
rotate += 0.05; // 旋转速度 reversal_end = Math.min(pogress_time() * ARC_LENGTH, ARC_LENGTH);
} if (reversal_end >= ARC_MAX) {
reversal_end = ARC_MAX
this.timer = setInterval(() => draw(), interval); foreward_end = 0
} startTime = Date.now();
}
} }
}
ctx.arc(
center,
center,
center - lineWidth,
startAngle + rotate + (reversal_end * Math.PI / 180),
startAngle + rotate + (foreward_end * Math.PI / 180)
);
ctx.lineWidth = lineWidth;
const fillColor = (this.color !== '' ? this.color : '#666').toString();
ctx.strokeStyle = fillColor;
ctx.stroke();
ctx.update();
rotate += 0.05; // 旋转速度
}
this.timer = setInterval(() => draw(), interval);
}
}
}
</script> </script>
<style scoped> <style scoped>
.block { .block {
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,
...@@ -77,4 +67,4 @@ ...@@ -77,4 +67,4 @@
transition-timing-function: linear; transition-timing-function: linear;
transform: rotate(0deg); transform: rotate(0deg);
} }
</style> </style>
\ No newline at end of file
...@@ -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'
...@@ -161,4 +161,4 @@ ...@@ -161,4 +161,4 @@
transform: rotate(0deg); transform: rotate(0deg);
} }
</style> </style>
\ No newline at end of file
{ {
"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.
先完成此消息的编辑!
想要评论请 注册