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