29
29
:key =" appLinkIndex"
30
30
:content =" appLink.path"
31
31
placement =" bottom"
32
+ :show-after =" 300"
32
33
>
33
34
<el-button
34
35
class =" m-b-8px m-r-8px m-l-0px!"
35
- :type =" isSameLink(appLink.path, activeAppLink) ? 'primary' : 'default'"
36
+ :type =" isSameLink(appLink.path, activeAppLink.path ) ? 'primary' : 'default'"
36
37
@click =" handleAppLinkSelected(appLink)"
37
38
>
38
39
{{ appLink.name }}
63
64
</Dialog >
64
65
</template >
65
66
<script lang="ts" setup>
66
- import { APP_LINK_GROUP_LIST , APP_LINK_TYPE_ENUM } from ' ./data'
67
+ import { APP_LINK_GROUP_LIST , APP_LINK_TYPE_ENUM , AppLink } from ' ./data'
67
68
import { ButtonInstance , ScrollbarInstance } from ' element-plus'
68
69
import { split } from ' lodash-es'
69
70
import ProductCategorySelect from ' @/views/mall/product/category/components/ProductCategorySelect.vue'
@@ -74,17 +75,23 @@ defineOptions({ name: 'AppLinkSelectDialog' })
74
75
// 选中的分组,默认选中第一个
75
76
const activeGroup = ref (APP_LINK_GROUP_LIST [0 ].name )
76
77
// 选中的 APP 链接
77
- const activeAppLink = ref (' ' )
78
+ const activeAppLink = ref ({} as AppLink )
78
79
79
80
/** 打开弹窗 */
80
81
const dialogVisible = ref (false )
81
82
const open = (link : string ) => {
82
- activeAppLink .value = link
83
+ activeAppLink .value . path = link
83
84
dialogVisible .value = true
84
85
85
86
// 滚动到当前的链接
86
87
const group = APP_LINK_GROUP_LIST .find ((group ) =>
87
- group .links .some ((linkItem ) => isSameLink (linkItem .path , link ))
88
+ group .links .some ((linkItem ) => {
89
+ const sameLink = isSameLink (linkItem .path , link )
90
+ if (sameLink ) {
91
+ activeAppLink .value = { ... linkItem , path: link }
92
+ }
93
+ return sameLink
94
+ })
88
95
)
89
96
if (group ) {
90
97
// 使用 nextTick 的原因:可能 Dom 还没生成,导致滚动失败
@@ -94,17 +101,17 @@ const open = (link: string) => {
94
101
defineExpose ({ open })
95
102
96
103
// 处理 APP 链接选中
97
- const handleAppLinkSelected = (appLink : any ) => {
98
- if (! isSameLink (appLink .path , activeAppLink .value )) {
99
- activeAppLink .value = appLink . path
104
+ const handleAppLinkSelected = (appLink : AppLink ) => {
105
+ if (! isSameLink (appLink .path , activeAppLink .value . path )) {
106
+ activeAppLink .value = appLink
100
107
}
101
108
switch (appLink .type ) {
102
109
case APP_LINK_TYPE_ENUM .PRODUCT_CATEGORY_LIST :
103
110
detailSelectDialog .value .visible = true
104
111
detailSelectDialog .value .type = appLink .type
105
112
// 返显
106
113
detailSelectDialog .value .id =
107
- getUrlNumberValue (' id' , ' http://127.0.0.1' + activeAppLink .value ) || undefined
114
+ getUrlNumberValue (' id' , ' http://127.0.0.1' + activeAppLink .value . path ) || undefined
108
115
break
109
116
default :
110
117
break
@@ -114,10 +121,12 @@ const handleAppLinkSelected = (appLink: any) => {
114
121
// 处理绑定值更新
115
122
const emit = defineEmits <{
116
123
change: [link : string ]
124
+ appLinkChange: [appLink : AppLink ]
117
125
}>()
118
126
const handleSubmit = () => {
119
127
dialogVisible .value = false
120
- emit (' change' , activeAppLink .value )
128
+ emit (' change' , activeAppLink .value .path )
129
+ emit (' appLinkChange' , activeAppLink .value )
121
130
}
122
131
123
132
// 分组标题引用列表
@@ -127,7 +136,7 @@ const groupTitleRefs = ref<HTMLInputElement[]>([])
127
136
* @param scrollTop 滚动条的位置
128
137
*/
129
138
const handleScroll = ({ scrollTop }: { scrollTop: number }) => {
130
- const titleEl = groupTitleRefs .value .find ((titleEl ) => {
139
+ const titleEl = groupTitleRefs .value .find ((titleEl : HTMLInputElement ) => {
131
140
// 获取标题的位置信息
132
141
const { offsetHeight, offsetTop } = titleEl
133
142
// 判断标题是否在可视范围内
@@ -146,7 +155,7 @@ const linkScrollbar = ref<ScrollbarInstance>()
146
155
// 处理分组选中
147
156
const handleGroupSelected = (group : string ) => {
148
157
activeGroup .value = group
149
- const titleRef = groupTitleRefs .value .find ((item ) => item .textContent === group )
158
+ const titleRef = groupTitleRefs .value .find ((item : HTMLInputElement ) => item .textContent === group )
150
159
if (titleRef ) {
151
160
// 滚动分组标题
152
161
linkScrollbar .value ?.setScrollTop (titleRef .offsetTop )
@@ -160,8 +169,8 @@ const groupBtnRefs = ref<ButtonInstance[]>([])
160
169
// 自动滚动分组按钮,确保分组按钮保持在可视区域内
161
170
const scrollToGroupBtn = (group : string ) => {
162
171
const groupBtn = groupBtnRefs .value
163
- .map ((btn ) => btn [' ref' ])
164
- .find ((ref ) => ref .textContent === group )
172
+ .map ((btn : ButtonInstance ) => btn [' ref' ])
173
+ .find ((ref : Node ) => ref .textContent === group )
165
174
if (groupBtn ) {
166
175
groupScrollbar .value ?.setScrollTop (groupBtn .offsetTop )
167
176
}
@@ -184,11 +193,11 @@ const detailSelectDialog = ref<{
184
193
})
185
194
// 处理详情选择
186
195
const handleProductCategorySelected = (id : number ) => {
187
- const url = new URL (activeAppLink .value , ' http://127.0.0.1' )
196
+ const url = new URL (activeAppLink .value . path , ' http://127.0.0.1' )
188
197
// 修改 id 参数
189
198
url .searchParams .set (' id' , ` ${id } ` )
190
199
// 排除域名
191
- activeAppLink .value = ` ${url .pathname }${url .search } `
200
+ activeAppLink .value . path = ` ${url .pathname }${url .search } `
192
201
// 关闭对话框
193
202
detailSelectDialog .value .visible = false
194
203
// 重置 id
0 commit comments