feat : 搜索新增专业/职位切换, 专业搜索时新增联想功能(接口待调)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="container">
|
<view class="container">
|
||||||
|
<view v-show="searchFocus" class="search-mask" ></view>
|
||||||
<view>
|
<view>
|
||||||
<view class="top">
|
<view class="top">
|
||||||
<image
|
<image
|
||||||
@@ -9,22 +10,46 @@
|
|||||||
@click="navBack"
|
@click="navBack"
|
||||||
></image>
|
></image>
|
||||||
<view class="search-box">
|
<view class="search-box">
|
||||||
<my-icons
|
<!-- 修改为左右布局的切换按钮 -->
|
||||||
class="iconsearch"
|
<view class="search-type-tabs">
|
||||||
color="#666666"
|
<view
|
||||||
type="search"
|
class="type-tab button-click"
|
||||||
size="36"
|
:class="{ active: searchType === 'job' }"
|
||||||
@confirm="searchCollection"
|
@click="setSearchType('job')"
|
||||||
></my-icons>
|
>
|
||||||
|
职位
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
class="type-tab button-click"
|
||||||
|
:class="{ active: searchType === 'major' }"
|
||||||
|
@click="setSearchType('major')"
|
||||||
|
>
|
||||||
|
专业
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
<input
|
<input
|
||||||
class="inputed"
|
class="inputed"
|
||||||
type="text"
|
type="text"
|
||||||
focus
|
focus
|
||||||
v-model="searchValue"
|
v-model="searchValue"
|
||||||
placeholder="搜索职位名称"
|
:placeholder="searchType === 'job' ? '搜索职位名称' : '搜索专业名称'"
|
||||||
placeholder-class="placeholder"
|
placeholder-class="placeholder"
|
||||||
|
@input="handleInputChange"
|
||||||
|
@blur="handleInputBlur"
|
||||||
|
@focus="handleInputFocus"
|
||||||
@confirm="searchBtn"
|
@confirm="searchBtn"
|
||||||
/>
|
/>
|
||||||
|
<!-- 联想搜索下拉列表 -->
|
||||||
|
<scroll-view scroll-y class="search-suggestions" v-show="showSuggestions && filteredSuggestions.length">
|
||||||
|
<view
|
||||||
|
class="suggestion-item"
|
||||||
|
v-for="(item, index) in filteredSuggestions"
|
||||||
|
:key="index"
|
||||||
|
@click="selectSuggestion(item)"
|
||||||
|
>
|
||||||
|
<view class="item-txt line_1">{{ item }}</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
<view class="search-btn button-click" @click="searchBtn">搜索</view>
|
<view class="search-btn button-click" @click="searchBtn">搜索</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -86,7 +111,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { inject, ref, reactive, nextTick } from 'vue';
|
import { inject, ref, reactive, nextTick, computed } from 'vue';
|
||||||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||||
import SelectJobs from '@/components/selectJobs/selectJobs.vue';
|
import SelectJobs from '@/components/selectJobs/selectJobs.vue';
|
||||||
const { $api, navBack, navTo } = inject('globalFunction');
|
const { $api, navBack, navTo } = inject('globalFunction');
|
||||||
@@ -100,10 +125,34 @@ import useUserStore from '@/stores/useUserStore';
|
|||||||
const { isMiniProgram } = storeToRefs(useUserStore());
|
const { isMiniProgram } = storeToRefs(useUserStore());
|
||||||
import { playTextDirectly } from '@/hook/useTTSPlayer-all-in-one';
|
import { playTextDirectly } from '@/hook/useTTSPlayer-all-in-one';
|
||||||
|
|
||||||
|
// 搜索类型:job-职位,major-专业
|
||||||
|
const searchType = ref('job');
|
||||||
const searchValue = ref('');
|
const searchValue = ref('');
|
||||||
const historyList = ref([]);
|
const historyList = ref([]);
|
||||||
const listCom = ref([]);
|
const listCom = ref([]);
|
||||||
|
const showSuggestions = ref(false);
|
||||||
|
const searchFocus = ref(false);
|
||||||
|
|
||||||
|
// 专业数据源(示例数据,可以替换为实际数据)
|
||||||
|
const majorDataSource = ref([]);
|
||||||
|
|
||||||
|
// 计算属性:过滤后的联想列表
|
||||||
|
const filteredSuggestions = computed(() => {
|
||||||
|
if (!searchValue.value || searchType.value !== 'major') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchText = searchValue.value.toLowerCase();
|
||||||
|
try {
|
||||||
|
return majorDataSource.value.filter(item =>
|
||||||
|
item.toLowerCase().includes(searchText)
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
const pageState = reactive({
|
const pageState = reactive({
|
||||||
page: 0,
|
page: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
@@ -117,7 +166,7 @@ const isLoaded = ref(false);
|
|||||||
const waterfallsFlowRef = ref(null);
|
const waterfallsFlowRef = ref(null);
|
||||||
const loadmoreRef = ref(null);
|
const loadmoreRef = ref(null);
|
||||||
const currentTab = ref(0);
|
const currentTab = ref(0);
|
||||||
// 响应式搜索条件(可以被修改)
|
|
||||||
const searchParams = ref({});
|
const searchParams = ref({});
|
||||||
const pageSize = ref(10);
|
const pageSize = ref(10);
|
||||||
|
|
||||||
@@ -166,8 +215,63 @@ onLoad((options) => {
|
|||||||
if (arr) {
|
if (arr) {
|
||||||
historyList.value = uni.getStorageSync('searchList');
|
historyList.value = uni.getStorageSync('searchList');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMajorDataSource()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getMajorDataSource() {
|
||||||
|
const LoadCache = (resData) => {
|
||||||
|
if (resData.code === 200) {
|
||||||
|
majorDataSource.value = resData.data;
|
||||||
|
console.log(majorDataSource.value)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置搜索类型并触发搜索
|
||||||
|
function setSearchType(type) {
|
||||||
|
if (searchType.value === type) return;
|
||||||
|
searchType.value = type;
|
||||||
|
|
||||||
|
// 如果输入框有值且当前是专业搜索,显示联想列表
|
||||||
|
if (searchValue.value && searchType.value === 'major' && searchFocus.value) {
|
||||||
|
showSuggestions.value = true;
|
||||||
|
} else {
|
||||||
|
showSuggestions.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果有搜索值,触发搜索
|
||||||
|
if (searchValue.value) {
|
||||||
|
// 重置页码
|
||||||
|
pageState.page = 0;
|
||||||
|
|
||||||
|
// 触发搜索
|
||||||
|
playTextDirectly('正在为您查找岗位')
|
||||||
|
|
||||||
|
// 根据搜索类型设置不同的参数
|
||||||
|
if (searchType.value === 'job') {
|
||||||
|
searchParams.value = {
|
||||||
|
jobTitle: searchValue.value,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
searchParams.value = {
|
||||||
|
majorTitle: searchValue.value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentTab.value === 0) {
|
||||||
|
getJobList('refresh');
|
||||||
|
} else {
|
||||||
|
refresh();
|
||||||
|
waterfallsFlowRef.value?.refresh?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏联想列表
|
||||||
|
showSuggestions.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function changeType(type) {
|
function changeType(type) {
|
||||||
if (currentTab.value === type) return;
|
if (currentTab.value === type) return;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -182,28 +286,84 @@ function changeType(type) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchFn(item) {
|
function searchFn(item) {
|
||||||
searchValue.value = item;
|
searchValue.value = item;
|
||||||
searchBtn();
|
searchBtn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleInputChange(e) {
|
||||||
|
const val = e.detail.value;
|
||||||
|
searchValue.value = val;
|
||||||
|
|
||||||
|
// 如果是专业搜索且输入框有值,显示联想列表
|
||||||
|
if (searchType.value === 'major' && val && searchFocus.value) {
|
||||||
|
showSuggestions.value = true;
|
||||||
|
} else {
|
||||||
|
showSuggestions.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInputFocus() {
|
||||||
|
searchFocus.value = true;
|
||||||
|
// 如果是专业搜索且输入框有值,显示联想列表
|
||||||
|
if (searchType.value === 'major' && searchValue.value) {
|
||||||
|
showSuggestions.value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInputBlur() {
|
||||||
|
searchFocus.value = false;
|
||||||
|
// 延迟隐藏联想列表,以便点击项能触发
|
||||||
|
setTimeout(() => {
|
||||||
|
showSuggestions.value = false;
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择联想项
|
||||||
|
function selectSuggestion(item) {
|
||||||
|
searchValue.value = item;
|
||||||
|
showSuggestions.value = false;
|
||||||
|
// 直接触发搜索
|
||||||
|
searchBtn();
|
||||||
|
}
|
||||||
|
|
||||||
function searchBtn() {
|
function searchBtn() {
|
||||||
if (!searchValue.value) {
|
if (!searchValue.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playTextDirectly('正在为您查找岗位')
|
playTextDirectly('正在为您查找岗位')
|
||||||
|
|
||||||
|
// 保存到历史记录(仅当搜索成功时保存)
|
||||||
historyList.value.unshift(searchValue.value);
|
historyList.value.unshift(searchValue.value);
|
||||||
historyList.value = unique(historyList.value);
|
historyList.value = unique(historyList.value);
|
||||||
uni.setStorageSync('searchList', historyList.value);
|
uni.setStorageSync('searchList', historyList.value);
|
||||||
|
|
||||||
|
// 根据搜索类型设置不同的参数
|
||||||
|
if (searchType.value === 'job') {
|
||||||
|
// 职位搜索
|
||||||
searchParams.value = {
|
searchParams.value = {
|
||||||
jobTitle: searchValue,
|
jobTitle: searchValue.value,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
// 专业搜索
|
||||||
|
searchParams.value = {
|
||||||
|
majorTitle: searchValue.value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置页码
|
||||||
|
pageState.page = 0;
|
||||||
|
|
||||||
if (currentTab.value === 0) {
|
if (currentTab.value === 0) {
|
||||||
getJobList('refresh');
|
getJobList('refresh');
|
||||||
} else {
|
} else {
|
||||||
refresh();
|
refresh();
|
||||||
waterfallsFlowRef.value?.refresh?.();
|
waterfallsFlowRef.value?.refresh?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 隐藏联想列表
|
||||||
|
showSuggestions.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchCollection(e) {
|
function searchCollection(e) {
|
||||||
@@ -254,13 +414,25 @@ function getJobList(type = 'add') {
|
|||||||
pageState.page = 1;
|
pageState.page = 1;
|
||||||
pageState.maxPage = 2;
|
pageState.maxPage = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据搜索类型构建参数
|
||||||
let params = {
|
let params = {
|
||||||
current: pageState.page,
|
current: pageState.page,
|
||||||
pageSize: pageState.pageSize,
|
pageSize: pageState.pageSize,
|
||||||
...pageState.search,
|
...pageState.search,
|
||||||
jobTitle: searchValue.value,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 移除之前的搜索参数,根据当前搜索类型添加
|
||||||
|
if (searchType.value === 'job') {
|
||||||
|
params.jobTitle = searchValue.value;
|
||||||
|
// 确保没有majorTitle参数
|
||||||
|
delete params.majorTitle;
|
||||||
|
} else {
|
||||||
|
params.majorTitle = searchValue.value;
|
||||||
|
// 确保没有jobTitle参数
|
||||||
|
delete params.jobTitle;
|
||||||
|
}
|
||||||
|
|
||||||
$api.createRequest('/app/job/list', params, 'GET', true).then((resData) => {
|
$api.createRequest('/app/job/list', params, 'GET', true).then((resData) => {
|
||||||
const { rows, total } = resData;
|
const { rows, total } = resData;
|
||||||
if (type === 'add') {
|
if (type === 'add') {
|
||||||
@@ -299,7 +471,6 @@ function dataToImg(data) {
|
|||||||
.Detailscroll-view{
|
.Detailscroll-view{
|
||||||
flex: 1
|
flex: 1
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
|
|
||||||
}
|
}
|
||||||
.container{
|
.container{
|
||||||
display: flex
|
display: flex
|
||||||
@@ -367,8 +538,6 @@ function dataToImg(data) {
|
|||||||
justify-content: space-between
|
justify-content: space-between
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
padding: 20rpx 20rpx;
|
padding: 20rpx 20rpx;
|
||||||
position: sticky;
|
|
||||||
top: 0
|
|
||||||
.btnback{
|
.btnback{
|
||||||
width: 60rpx;
|
width: 60rpx;
|
||||||
height: 60rpx;
|
height: 60rpx;
|
||||||
@@ -376,9 +545,43 @@ function dataToImg(data) {
|
|||||||
.search-box{
|
.search-box{
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 0 24rpx 0 6rpx;
|
padding: 0 24rpx 0 6rpx;
|
||||||
position: relative
|
position: relative;
|
||||||
|
z-index: 10;
|
||||||
|
.search-type-tabs {
|
||||||
|
background: #FFFFFF;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 21rpx;
|
||||||
|
transform: translate(0, -50%);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
padding: 4rpx;
|
||||||
|
z-index: 2;
|
||||||
|
border: 1rpx solid #E0E0E0;
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
|
||||||
|
border-radius: 60rpx
|
||||||
|
|
||||||
|
.type-tab {
|
||||||
|
padding: 10rpx 24rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #666666;
|
||||||
|
border-radius: 30rpx;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: #256BFA;
|
||||||
|
color: #FFFFFF;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.type-tab:first-child {
|
||||||
|
margin-right: 1rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
.inputed {
|
.inputed {
|
||||||
padding-left: 30rpx
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: #F8F8F8;
|
background: #F8F8F8;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
@@ -386,17 +589,46 @@ function dataToImg(data) {
|
|||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 36rpx;
|
line-height: 36rpx;
|
||||||
color: #666666;
|
color: #666666;
|
||||||
padding: 0 30rpx 0 80rpx;
|
padding: 0 30rpx 0 230rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
height: 80rpx;
|
height: 80rpx;
|
||||||
background: #F5F5F5;
|
background: #F5F5F5;
|
||||||
border-radius: 75rpx 75rpx 75rpx 75rpx;
|
border-radius: 73rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-suggestions {
|
||||||
|
position: absolute;
|
||||||
|
top: 105%;
|
||||||
|
width:calc(100% - 24rpx - 6rpx);
|
||||||
|
background: #FFFFFF;
|
||||||
|
border: 2rpx solid #ECECEC;
|
||||||
|
border-top: 0;
|
||||||
|
z-index: 10;
|
||||||
|
border-radius: 30rpx
|
||||||
|
max-height: 40vh;
|
||||||
|
overflow hidden;
|
||||||
|
.suggestion-item {
|
||||||
|
height: 80rpx;
|
||||||
|
padding: 0rpx 24rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-items: flex-start;
|
||||||
|
border-top: 2rpx dashed #e3e3e3;
|
||||||
|
|
||||||
|
.item-txt {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333333;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.suggestion-item:hover {
|
||||||
|
background: #e5e5e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.suggestion-item:first-child {
|
||||||
|
border-top: none;
|
||||||
}
|
}
|
||||||
.iconsearch{
|
|
||||||
position: absolute
|
|
||||||
top: 50%
|
|
||||||
left: 36rpx
|
|
||||||
transform: translate(0, -50%)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.search-btn {
|
.search-btn {
|
||||||
@@ -473,4 +705,13 @@ function dataToImg(data) {
|
|||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #6C7282;
|
color: #6C7282;
|
||||||
margin-top: 6rpx;
|
margin-top: 6rpx;
|
||||||
|
.search-mask{
|
||||||
|
position fixed;
|
||||||
|
width 100vw;
|
||||||
|
height:100vh;
|
||||||
|
top:0;
|
||||||
|
left:0
|
||||||
|
z-index:9;
|
||||||
|
background: #33333355;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user