Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mayi-mp-shop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
程默
mayi-mp-shop
Commits
da2c6dcd
Commit
da2c6dcd
authored
Apr 25, 2023
by
howie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:搜索组件新增热门词
parent
e3e7de2f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
3 deletions
+88
-3
src/api/goods.js
+4
-0
static/nativeComponents/GoodsSearch/index.js
+50
-3
static/nativeComponents/GoodsSearch/index.wxml
+8
-0
static/nativeComponents/GoodsSearch/index.wxss
+26
-0
No files found.
src/api/goods.js
View file @
da2c6dcd
import
{
requestPOST
,
requestGET
}
from
"@/utils/request.js"
;
import
{
requestPOST
,
requestGET
}
from
"@/utils/request.js"
;
export
default
{
export
default
{
// 获取搜索热门词
getHotWordsApi
(
data
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/product/query_popular_words_shop`
,
data
);
},
queryProductInfo
(
data
)
{
queryProductInfo
(
data
)
{
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/product/query_product_info`
,
data
);
return
requestPOST
(
`
${
process
.
env
.
OLSHOP_URL
}
/product/query_product_info`
,
data
);
},
},
...
...
static/nativeComponents/GoodsSearch/index.js
View file @
da2c6dcd
...
@@ -9,7 +9,6 @@ Component({
...
@@ -9,7 +9,6 @@ Component({
type
:
Object
type
:
Object
}
}
},
},
/**
/**
* 组件的初始数据
* 组件的初始数据
*/
*/
...
@@ -18,7 +17,9 @@ Component({
...
@@ -18,7 +17,9 @@ Component({
backgroundColor
:
''
,
backgroundColor
:
''
,
borderColor
:
''
,
borderColor
:
''
,
placeholderValue
:
''
,
placeholderValue
:
''
,
searchScopeFlag
:
0
searchScopeFlag
:
0
,
tableData
:
[],
hotWordsInterval
:
null
// 热门词轮播定时任务
},
},
ready
(){
ready
(){
this
.
setData
({
this
.
setData
({
...
@@ -41,12 +42,58 @@ Component({
...
@@ -41,12 +42,58 @@ Component({
this
.
setData
({
this
.
setData
({
placeholderValue
:
this
.
data
.
datas
.
componentData
.
placeHolderVal
?
this
.
data
.
datas
.
componentData
.
placeHolderVal
:
'搜索店铺内'
placeholderValue
:
this
.
data
.
datas
.
componentData
.
placeHolderVal
?
this
.
data
.
datas
.
componentData
.
placeHolderVal
:
'搜索店铺内'
})
})
},
this
.
getHotWords
()
},
detached
()
{
clearInterval
(
this
.
data
.
hotWordsInterval
)
this
.
data
.
hotWordsInterval
=
null
;
console
.
log
(
"销毁"
,
this
.
data
.
hotWordsInterval
);
},
/**
/**
* 组件的方法列表
* 组件的方法列表
*/
*/
methods
:
{
methods
:
{
getHotWords
()
{
app
.
goodsApi
.
getHotWordsApi
({}).
then
(({
data
:{
data
}})
=>
{
if
(
data
)
{
function
compare
(
property
)
{
return
function
(
a
,
b
)
{
var
value1
=
a
[
property
];
var
value2
=
b
[
property
];
return
value1
-
value2
;
};
}
data
.
sort
(
compare
(
"sequenceNumber"
));
this
.
setData
({
tableData
:
data
})
if
(
this
.
data
.
datas
.
componentData
.
hotWordsData
[
"isOpenHotWords"
]
==
1
)
{
this
.
hotWordsCarousel
();
}
}
})
},
// 热门词轮播方法
hotWordsCarousel
()
{
console
.
log
(
"调用定时渲染任务2"
);
if
(
this
.
data
.
tableData
.
length
>
0
)
{
let
currentIndex
=
0
;
// 当前取到的元素下标
// 初始化placeholderVal
const
placeHolderVal
=
'datas.componentData.placeHolderVal'
this
.
setData
({
[
placeHolderVal
]:
this
.
data
.
tableData
[
0
].
popularWordsName
,
// 用于搜索
placeholderValue
:
this
.
data
.
tableData
[
0
].
popularWordsName
// 用于显示
})
this
.
data
.
hotWordsInterval
=
setInterval
(()
=>
{
// 取出下一个元素
currentIndex
=
(
currentIndex
+
1
)
%
this
.
data
.
tableData
.
length
;
console
.
log
(
"有无"
,
this
.
data
.
tableData
[
currentIndex
].
popularWordsName
);
this
.
setData
({
[
placeHolderVal
]:
this
.
data
.
tableData
[
currentIndex
].
popularWordsName
,
placeholderValue
:
this
.
data
.
tableData
[
currentIndex
].
popularWordsName
})
},
5000
);
}
},
toSearchPage
(
e
){
toSearchPage
(
e
){
if
(
this
.
data
.
datas
.
componentData
[
'searchModel'
]
==
1
)
return
;
if
(
this
.
data
.
datas
.
componentData
[
'searchModel'
]
==
1
)
return
;
app
.
trackCpn
(
e
,
this
.
data
.
datas
.
componentName
)
app
.
trackCpn
(
e
,
this
.
data
.
datas
.
componentName
)
...
...
static/nativeComponents/GoodsSearch/index.wxml
View file @
da2c6dcd
...
@@ -23,3 +23,11 @@
...
@@ -23,3 +23,11 @@
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 热门词区域 -->
<view class="hot_words_class" wx:if="{{datas.componentData.hotWordsData['isOpenHotWords'] == 1}}">
<view class="hot_words_box">
<view class="words_item" wx:for="{{tableData}}" wx:key="id" style="font-size:{{datas.componentData.hotWordsData.hotWordsTextIsDefault==1 ? datas.componentData.hotWordsData.fontSize + 'px' : ''}};color:{{datas.componentData.hotWordsData.hotWordsTextIsDefault==1 ? datas.componentData.hotWordsData.color : ''}};background-color:{{datas.componentData.hotWordsData.hotWordsBackgroundIsDefault==1 ? datas.componentData.hotWordsData.backgroundColor : ''}}">
{{ item.popularWordsName }}
</view>
</view>
</view>
static/nativeComponents/GoodsSearch/index.wxss
View file @
da2c6dcd
...
@@ -71,3 +71,29 @@
...
@@ -71,3 +71,29 @@
width: 15px;
width: 15px;
height: 15px;
height: 15px;
}
}
.hot_words_class {
width:100%;
padding: 0 8px;
}
.hot_words_box {
display: flex;
justify-content: start;
width: 100%;
overflow: hidden;
overflow-x: scroll;
white-space: nowrap;
text-align: center;
margin-top: 4px;
}
.words_item {
padding: 2px 8px;
margin-right: 8px;
color:#ffffff;
font-size: 12px;
background-color:rgba(255, 255, 255, 0.2);
flex-shrink: 0;
border-radius: 11px;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment