@tplc/wot 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/components/composables/useTranslate.ts +1 -1
- package/components/wd-img/types.ts +3 -1
- package/components/wd-img/wd-img.vue +24 -9
- package/components/wd-index-anchor/type.ts +2 -1
- package/components/wd-index-anchor/wd-index-anchor.vue +9 -7
- package/components/wd-index-bar/type.ts +1 -7
- package/components/wd-index-bar/wd-index-bar.vue +29 -16
- package/package.json +1 -1
- package/types/components/wd-img/types.d.ts +1 -0
- package/types/components/wd-img/wd-img.vue.d.ts +2 -0
- package/types/components/wd-index-anchor/type.d.ts +4 -0
- package/types/components/wd-index-anchor/wd-index-anchor.vue.d.ts +12 -1
- package/types/components/wd-index-bar/type.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.13](http://gitlab888.30jia.com.cn/bhBank/zero-code-pro/compare/v0.0.27...v0.1.13) (2024-10-10)
|
|
6
|
+
|
|
5
7
|
### [0.1.12](http://gitlab888.30jia.com.cn/bhBank/zero-code-pro/compare/v0.1.11...v0.1.12) (2024-09-27)
|
|
6
8
|
|
|
7
9
|
### [0.1.11](http://gitlab888.30jia.com.cn/bhBank/zero-code-pro/compare/v0.0.26...v0.1.11) (2024-09-27)
|
|
@@ -16,7 +16,7 @@ export const useTranslate = (name?: string) => {
|
|
|
16
16
|
const translate = (key: string, ...args: unknown[]) => {
|
|
17
17
|
const currentMessages = Locale.messages()
|
|
18
18
|
const message = getPropByPath(currentMessages, prefix + key)
|
|
19
|
-
return isFunction(message) ? message(...args) : message
|
|
19
|
+
return (isFunction(message) ? message(...args) : message) || key
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
return { translate }
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view :class="rootClass" @click="handleClick" :style="rootStyle">
|
|
3
|
-
<image
|
|
4
|
-
:
|
|
5
|
-
|
|
6
|
-
:
|
|
7
|
-
:mode="mode"
|
|
8
|
-
:lazy-load="lazyLoad"
|
|
9
|
-
@load="handleLoad"
|
|
10
|
-
@error="handleError"
|
|
11
|
-
/>
|
|
3
|
+
<image :class="`wd-img__image coverImg ${customImage}`" :src="wrapPhoto({ photo: src, width, type: 2 })"
|
|
4
|
+
:mode="mode" :style="status != 'success' && {
|
|
5
|
+
...wrapPhoto({ photo: src, width: lazyPlaceWidth })
|
|
6
|
+
}" :lazy-load="lazyLoad" @load="handleLoad" @error="handleError" />
|
|
12
7
|
<slot v-if="status === 'loading'" name="loading"></slot>
|
|
13
8
|
<slot v-if="status === 'error'" name="error"></slot>
|
|
14
9
|
</view>
|
|
@@ -22,6 +17,7 @@ export default {
|
|
|
22
17
|
styleIsolation: 'shared',
|
|
23
18
|
},
|
|
24
19
|
}
|
|
20
|
+
//:style="`${status !== 'success' ? 'width: 0;height: 0;' : ''}`"
|
|
25
21
|
</script>
|
|
26
22
|
|
|
27
23
|
<script lang="ts" setup>
|
|
@@ -69,8 +65,27 @@ function handleLoad(event: Event) {
|
|
|
69
65
|
status.value = 'success'
|
|
70
66
|
emit('load', event)
|
|
71
67
|
}
|
|
68
|
+
|
|
69
|
+
function wrapPhoto({
|
|
70
|
+
photo,
|
|
71
|
+
width = 200,
|
|
72
|
+
otherParams = {},
|
|
73
|
+
type = 1,
|
|
74
|
+
}: any) {
|
|
75
|
+
const isctyun = photo?.indexOf('.ctyun') >= 0;
|
|
76
|
+
const sym = photo?.indexOf('?') > 0 ? '&' : '?';
|
|
77
|
+
const suffix = isctyun ? `${sym}x-amz-process=image/resize,w_${width},m_lfit` : `${sym}x-oss-process=image/resize,m_mfit,w_${width}&imageView2/2/w/${width}`;
|
|
78
|
+
const url = `${photo}${width > 0 ? suffix : ''}`;
|
|
79
|
+
return type == 2 ? url : photo ? { backgroundImage: `url('${url}')`, ...otherParams } : otherParams;
|
|
80
|
+
}
|
|
81
|
+
|
|
72
82
|
</script>
|
|
73
83
|
|
|
74
84
|
<style lang="scss" scoped>
|
|
75
85
|
@import './index.scss';
|
|
86
|
+
|
|
87
|
+
.coverImg {
|
|
88
|
+
background-repeat: no-repeat;
|
|
89
|
+
background-size: cover;
|
|
90
|
+
}
|
|
76
91
|
</style>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ExtractPropTypes } from 'vue'
|
|
2
|
-
import { baseProps, makeRequiredProp } from '../common/props'
|
|
2
|
+
import { baseProps, makeRequiredProp, makeStringProp } from '../common/props'
|
|
3
3
|
|
|
4
4
|
export const indexAnchorProps = {
|
|
5
5
|
...baseProps,
|
|
6
6
|
index: makeRequiredProp([String, Number]),
|
|
7
|
+
hint: makeStringProp(''),
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export type IndexAnchorProps = ExtractPropTypes<typeof indexAnchorProps>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
:id="indexAnchorId"
|
|
9
9
|
>
|
|
10
10
|
<slot>
|
|
11
|
-
{{ index }}
|
|
11
|
+
{{ hint || index }}
|
|
12
12
|
</slot>
|
|
13
13
|
</view>
|
|
14
14
|
<!-- #ifdef MP-DINGTALK -->
|
|
@@ -31,6 +31,8 @@ const indexAnchorId = ref<string>(`indexBar${uuid()}`)
|
|
|
31
31
|
|
|
32
32
|
const { proxy } = getCurrentInstance()!
|
|
33
33
|
|
|
34
|
+
const top = ref<number>(0)
|
|
35
|
+
|
|
34
36
|
const isSticky = computed(() => {
|
|
35
37
|
return indexBar && indexBar.props.sticky && indexBar.anchorState.activeIndex === props.index
|
|
36
38
|
})
|
|
@@ -38,20 +40,20 @@ const isSticky = computed(() => {
|
|
|
38
40
|
function getInfo() {
|
|
39
41
|
getRect(`#${indexAnchorId.value}`, false, proxy).then((res) => {
|
|
40
42
|
if (isDef(indexBar)) {
|
|
41
|
-
|
|
42
|
-
anchor.top = Math.floor(res.top!)
|
|
43
|
+
top.value = Math.floor(res.top!)
|
|
43
44
|
}
|
|
44
45
|
})
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
onMounted(() => {
|
|
48
|
-
if (isDef(indexBar)) {
|
|
49
|
-
indexBar.anchorState.anchorList.push({ top: 0, index: props.index })
|
|
50
|
-
}
|
|
51
49
|
getInfo()
|
|
52
50
|
})
|
|
51
|
+
|
|
52
|
+
defineExpose({
|
|
53
|
+
top,
|
|
54
|
+
})
|
|
53
55
|
</script>
|
|
54
56
|
|
|
55
57
|
<style lang="scss" scoped>
|
|
56
|
-
@import './index';
|
|
58
|
+
@import './index.scss';
|
|
57
59
|
</style>
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InjectionKey, ExtractPropTypes } from 'vue'
|
|
2
2
|
import { makeBooleanProp } from '../common/props'
|
|
3
3
|
|
|
4
4
|
export type AnchorIndex = number | string
|
|
5
5
|
|
|
6
|
-
export interface AnchorItem {
|
|
7
|
-
top: number
|
|
8
|
-
index: AnchorIndex
|
|
9
|
-
}
|
|
10
|
-
|
|
11
6
|
export const indexBarProps = {
|
|
12
7
|
/**
|
|
13
8
|
* @description 索引是否吸顶
|
|
@@ -20,7 +15,6 @@ export type IndexBarProps = ExtractPropTypes<typeof indexBarProps>
|
|
|
20
15
|
export type InderBarProvide = {
|
|
21
16
|
props: { sticky?: boolean }
|
|
22
17
|
anchorState: {
|
|
23
|
-
anchorList: AnchorItem[] // 锚点列表
|
|
24
18
|
activeIndex: AnchorIndex | null // 当前激活的索引
|
|
25
19
|
}
|
|
26
20
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
<view
|
|
22
22
|
class="wd-index-bar__index"
|
|
23
23
|
:class="{ 'is-active': item.index === state.activeIndex }"
|
|
24
|
-
v-for="item in
|
|
24
|
+
v-for="item in children"
|
|
25
25
|
:key="item.index"
|
|
26
26
|
>
|
|
27
27
|
{{ item.index }}
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
</template>
|
|
35
35
|
|
|
36
36
|
<script setup lang="ts">
|
|
37
|
-
import type {
|
|
37
|
+
import type { AnchorIndex } from './type'
|
|
38
38
|
import { indexBarInjectionKey, indexBarProps } from './type'
|
|
39
|
-
import { ref, getCurrentInstance, onMounted, reactive, nextTick } from 'vue'
|
|
39
|
+
import { ref, getCurrentInstance, onMounted, reactive, nextTick, watch } from 'vue'
|
|
40
40
|
import { getRect, isDef, uuid, requestAnimationFrame } from '../common/util'
|
|
41
41
|
import { useChildren } from '../composables/useChildren'
|
|
42
42
|
|
|
@@ -48,13 +48,27 @@ const { proxy } = getCurrentInstance()!
|
|
|
48
48
|
|
|
49
49
|
const state = reactive({
|
|
50
50
|
activeIndex: null as AnchorIndex | null,
|
|
51
|
-
anchorList: [] as AnchorItem[],
|
|
52
51
|
})
|
|
53
52
|
|
|
54
|
-
const { linkChildren } = useChildren(indexBarInjectionKey)
|
|
53
|
+
const { linkChildren, children } = useChildren(indexBarInjectionKey)
|
|
55
54
|
|
|
56
55
|
linkChildren({ props, anchorState: state })
|
|
57
56
|
|
|
57
|
+
watch(
|
|
58
|
+
() => children,
|
|
59
|
+
(newValue) => {
|
|
60
|
+
if (!newValue.length) {
|
|
61
|
+
state.activeIndex = null // 或者设置为一个默认值,如第一个子项的索引
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!isDef(state.activeIndex) || !newValue.find((item) => item.index === state.activeIndex)) {
|
|
66
|
+
state.activeIndex = newValue[0].index
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{ deep: true, immediate: true },
|
|
70
|
+
)
|
|
71
|
+
|
|
58
72
|
const scrollState = reactive({
|
|
59
73
|
scrollTop: 0, // 即将滚动到的位置
|
|
60
74
|
prevScrollTop: 0, // 上次记录的位置
|
|
@@ -73,7 +87,6 @@ const sidebarInfo = {
|
|
|
73
87
|
|
|
74
88
|
function init() {
|
|
75
89
|
setTimeout(() => {
|
|
76
|
-
state.activeIndex = state.anchorList[0]?.index
|
|
77
90
|
Promise.all([
|
|
78
91
|
getRect(`#${indexBarId.value}`, false, proxy),
|
|
79
92
|
getRect('.wd-index-bar__sidebar', false, proxy),
|
|
@@ -96,16 +109,16 @@ function hanleScroll(scrollEvent: any) {
|
|
|
96
109
|
}
|
|
97
110
|
const { detail } = scrollEvent
|
|
98
111
|
const scrolltop = Math.floor(detail.scrollTop)
|
|
99
|
-
const anchor =
|
|
100
|
-
if (!isDef(
|
|
112
|
+
const anchor = children.find((item, index) => {
|
|
113
|
+
if (!isDef(children[index + 1])) return true
|
|
101
114
|
if (
|
|
102
|
-
item.
|
|
103
|
-
|
|
115
|
+
item.$.exposed!.top.value - offsetTop <= scrolltop &&
|
|
116
|
+
children[index + 1].$.exposed!.top.value - offsetTop > scrolltop
|
|
104
117
|
)
|
|
105
118
|
return true
|
|
106
119
|
return false
|
|
107
|
-
})
|
|
108
|
-
if (state.activeIndex !== anchor.index) {
|
|
120
|
+
})
|
|
121
|
+
if (isDef(anchor) && state.activeIndex !== anchor.index) {
|
|
109
122
|
state.activeIndex = anchor.index
|
|
110
123
|
}
|
|
111
124
|
scrollState.prevScrollTop = scrolltop
|
|
@@ -115,8 +128,8 @@ function getAnchorByPageY(pageY: number) {
|
|
|
115
128
|
const y = pageY - sidebarInfo.offsetTop
|
|
116
129
|
let idx = Math.floor(y / sidebarInfo.indexHeight)
|
|
117
130
|
if (idx < 0) idx = 0
|
|
118
|
-
else if (idx >
|
|
119
|
-
return
|
|
131
|
+
else if (idx > children.length - 1) idx = children.length - 1
|
|
132
|
+
return children[idx]
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
function handleTouchStart() {
|
|
@@ -129,13 +142,13 @@ function handleTouchMove(e: TouchEvent) {
|
|
|
129
142
|
return
|
|
130
143
|
}
|
|
131
144
|
state.activeIndex = getAnchorByPageY(clientY).index
|
|
132
|
-
setScrollTop(getAnchorByPageY(clientY).
|
|
145
|
+
setScrollTop(getAnchorByPageY(clientY).$.exposed!.top.value - offsetTop)
|
|
133
146
|
}
|
|
134
147
|
|
|
135
148
|
function handleTouchEnd(e: TouchEvent) {
|
|
136
149
|
const clientY = e.changedTouches[0].pageY
|
|
137
150
|
state.activeIndex = getAnchorByPageY(clientY).index
|
|
138
|
-
setScrollTop(getAnchorByPageY(clientY).
|
|
151
|
+
setScrollTop(getAnchorByPageY(clientY).$.exposed!.top.value - offsetTop)
|
|
139
152
|
requestAnimationFrame(() => {
|
|
140
153
|
scrollState.touching = false
|
|
141
154
|
})
|
package/package.json
CHANGED
|
@@ -25,6 +25,7 @@ declare const _default: __VLS_WithTemplateSlots<
|
|
|
25
25
|
type: BooleanConstructor
|
|
26
26
|
default: boolean
|
|
27
27
|
}
|
|
28
|
+
lazyPlaceWidth: (NumberConstructor | StringConstructor)[]
|
|
28
29
|
customStyle: {
|
|
29
30
|
type: import('vue').PropType<string>
|
|
30
31
|
default: string
|
|
@@ -73,6 +74,7 @@ declare const _default: __VLS_WithTemplateSlots<
|
|
|
73
74
|
type: BooleanConstructor
|
|
74
75
|
default: boolean
|
|
75
76
|
}
|
|
77
|
+
lazyPlaceWidth: (NumberConstructor | StringConstructor)[]
|
|
76
78
|
customStyle: {
|
|
77
79
|
type: import('vue').PropType<string>
|
|
78
80
|
default: string
|
|
@@ -7,6 +7,10 @@ declare const __VLS_component: import('vue').DefineComponent<
|
|
|
7
7
|
type: (NumberConstructor | StringConstructor)[]
|
|
8
8
|
required: true
|
|
9
9
|
}
|
|
10
|
+
hint: {
|
|
11
|
+
type: import('vue').PropType<string>
|
|
12
|
+
default: string
|
|
13
|
+
}
|
|
10
14
|
customStyle: {
|
|
11
15
|
type: import('vue').PropType<string>
|
|
12
16
|
default: string
|
|
@@ -16,7 +20,9 @@ declare const __VLS_component: import('vue').DefineComponent<
|
|
|
16
20
|
default: string
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
|
-
{
|
|
23
|
+
{
|
|
24
|
+
top: import('vue').Ref<number>
|
|
25
|
+
},
|
|
20
26
|
unknown,
|
|
21
27
|
{},
|
|
22
28
|
{},
|
|
@@ -31,6 +37,10 @@ declare const __VLS_component: import('vue').DefineComponent<
|
|
|
31
37
|
type: (NumberConstructor | StringConstructor)[]
|
|
32
38
|
required: true
|
|
33
39
|
}
|
|
40
|
+
hint: {
|
|
41
|
+
type: import('vue').PropType<string>
|
|
42
|
+
default: string
|
|
43
|
+
}
|
|
34
44
|
customStyle: {
|
|
35
45
|
type: import('vue').PropType<string>
|
|
36
46
|
default: string
|
|
@@ -44,6 +54,7 @@ declare const __VLS_component: import('vue').DefineComponent<
|
|
|
44
54
|
{
|
|
45
55
|
customStyle: string
|
|
46
56
|
customClass: string
|
|
57
|
+
hint: string
|
|
47
58
|
},
|
|
48
59
|
{}
|
|
49
60
|
>
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { InjectionKey, ExtractPropTypes } from 'vue'
|
|
2
2
|
export type AnchorIndex = number | string
|
|
3
|
-
export interface AnchorItem {
|
|
4
|
-
top: number
|
|
5
|
-
index: AnchorIndex
|
|
6
|
-
}
|
|
7
3
|
export declare const indexBarProps: {
|
|
8
4
|
/**
|
|
9
5
|
* @description 索引是否吸顶
|
|
@@ -19,7 +15,6 @@ export type InderBarProvide = {
|
|
|
19
15
|
sticky?: boolean
|
|
20
16
|
}
|
|
21
17
|
anchorState: {
|
|
22
|
-
anchorList: AnchorItem[]
|
|
23
18
|
activeIndex: AnchorIndex | null
|
|
24
19
|
}
|
|
25
20
|
}
|