721 lines
18 KiB
Vue
721 lines
18 KiB
Vue
<template>
|
|
<view class="home-page">
|
|
<z-paging ref="paging" :auto="false" v-model="contList" @query="queryList" empty-view-text="暂无数据!">
|
|
<!-- <template #top> -->
|
|
<!-- 轮播Banner -->
|
|
<swiper class="banner-swiper" circular autoplay :interval="4000" indicator-dots indicator-color="rgba(255,255,255,.4)"
|
|
indicator-active-color="#3F435B">
|
|
<swiper-item v-for="(banner,index) in bannerList" :key="index">
|
|
<image class="banner-img" :src="banner.image_url_pull" mode="aspectFill"></image>
|
|
<!-- <view class="banner-desc">
|
|
<text class="slogan-text">{{banner.slogan}}</text>
|
|
</view> -->
|
|
</swiper-item>
|
|
</swiper>
|
|
<!-- </template> -->
|
|
<!-- 内容网格 -->
|
|
<!-- <u-sticky offset-top="40"> -->
|
|
<view class="search">
|
|
<view class="search-input-wrapper">
|
|
<view class="search-input-box">
|
|
<view v-if="searchTag" class="search-tag">
|
|
<text>{{searchTag}}</text>
|
|
<uni-icons type="closeempty" size="14" color="#666" @click="removeSearchTag"></uni-icons>
|
|
</view>
|
|
<input
|
|
class="search-input"
|
|
:placeholder="searchTag ? '' : '请输入搜索内容'"
|
|
v-model="searchKeyword"
|
|
@confirm="handleSearch"
|
|
@input="handleSearchInput"
|
|
/>
|
|
<uni-icons type="search" size="18" color="#909399" @click="handleSearch"></uni-icons>
|
|
</view>
|
|
</view>
|
|
<view class="sort-options">
|
|
<view
|
|
class="sort-item"
|
|
:class="{active: sortField === 'browse'}"
|
|
@click="toggleSort('browse')"
|
|
>
|
|
<text>观看量</text>
|
|
<view class="">
|
|
<u-icon name="arrow-up-fill" size="8" :color="sortField === 'browse'&&sortOrder === 'asc' ? '#206ff4' : '#666'"></u-icon>
|
|
<u-icon name="arrow-down-fill" size="8" :color="sortField === 'browse'&&sortOrder === 'desc' ? '#206ff4' : '#666'" ></u-icon>
|
|
</view>
|
|
<!-- <uni-icons
|
|
:type="sortField === 'like' ? (sortOrder === 'desc' ? 'arrowdown' : 'arrowup') : 'arrowup'"
|
|
:color="sortField === 'like' ? '#206ff4' : '#666'"
|
|
size="14"
|
|
></uni-icons> -->
|
|
</view>
|
|
<view
|
|
class="sort-item"
|
|
:class="{active: sortField === 'favorite'}"
|
|
@click="toggleSort('favorite')"
|
|
>
|
|
<text>收藏量</text>
|
|
<view class="">
|
|
<u-icon name="arrow-up-fill" size="8" :color="sortField === 'favorite'&&sortOrder === 'asc' ? '#206ff4' : '#666'"></u-icon>
|
|
<u-icon name="arrow-down-fill" size="8" :color="sortField === 'favorite'&&sortOrder === 'desc' ? '#206ff4' : '#666'" ></u-icon>
|
|
</view>
|
|
<!-- <uni-icons
|
|
:type="sortField === 'favorite' ? (sortOrder === 'desc' ? 'arrowdown' : 'arrowup') : 'arrowup'"
|
|
:color="sortField === 'favorite' ? '#206ff4' : '#666'"
|
|
size="14"
|
|
></uni-icons> -->
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<!-- </u-sticky> -->
|
|
<view class="content-grid">
|
|
<square-post-card
|
|
class="grid-item"
|
|
v-for="sitem in contList"
|
|
:key="sitem.id"
|
|
:item="sitem"
|
|
:isshow="false"
|
|
@view="navToList"
|
|
@comment="viewPost"
|
|
@like="viewPost" />
|
|
</view>
|
|
</z-paging>
|
|
|
|
<u-popup :show="show" :closeOnClickOverlay="false" :round="20" mode="center">
|
|
<view class="popupcontent">
|
|
<image class="log1" src="/static/image/log1.png"></image>
|
|
<view class="title">{{$t('home.loginmsg')}}</view>
|
|
<view class="yhxy">
|
|
<checkbox-group name="" style="width: 28px;display: inline-block;">
|
|
<label @tap="selfChangde()">
|
|
<checkbox :checked="selfChecked" activeBackgroundColor="#3F435B"
|
|
style="transform:scale(0.7);border-radius: 50%" />
|
|
</label>
|
|
</checkbox-group>
|
|
{{$t('home.argin')}}<text class="xy" @click="gouser">{{$t('home.UserAgreement')}}</text>{{$t('home.and')}}<text
|
|
class="xy" @click="goprivacy">{{$t('home.Privacy')}}</text>
|
|
</view>
|
|
</view>
|
|
<view class="cent">
|
|
<button class="btn1" @click="show = !show">{{$t('cancel')}}</button>
|
|
<button v-if="selfChecked" class="btn" open-type="getPhoneNumber" @click="show = !show"
|
|
@getphonenumber="getPhoneNumber">{{$t('login')}}</button>
|
|
<button v-else class="btn" @click="loginbtn">{{$t('login')}}</button>
|
|
</view>
|
|
</u-popup>
|
|
|
|
<u-picker :immediateChange="true" :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" @close="close('showlang')"
|
|
:show="showlang" :columns="columns" @cancel="cancellang" @confirm="confirmlang" :title="$t('home.langbtn')" keyName="label"></u-picker>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { request,showToast } from '@/api/apiT.js'
|
|
import SquarePostCard from '@/components/SquarePostCard.vue'
|
|
import uInput from '@/uni_modules/uview-ui/components/u-input/u-input.vue'
|
|
// import uSticky from '@/uni_modules/uview-ui/components/u-sticky/u-sticky.vue'
|
|
|
|
export default {
|
|
components: {
|
|
SquarePostCard,uInput
|
|
},
|
|
data() {
|
|
return {
|
|
title: 'Hello',
|
|
selfChecked: false,
|
|
home: this.$t('tabbar.home'),
|
|
is_login:uni.getStorageSync('is_login'),
|
|
show: false,
|
|
showlang: false,
|
|
searchKeyword: '',
|
|
searchTag: '', // 搜索标签(如 #包豪斯)
|
|
bannerList: [],
|
|
contList: [],
|
|
sortField: '', // 排序字段:''(时间) 或 'browse'(观看量) 或 'favorite'(收藏量)
|
|
sortOrder: 'desc', // 排序方向:'asc' 升序 或 'desc' 降序
|
|
columns: [
|
|
[{
|
|
label: this.$t('zh'),
|
|
id: 'zh'
|
|
}, {
|
|
label: this.$t('en'),
|
|
id: 'en'
|
|
},{
|
|
label: this.$t('ru'),
|
|
id: 'ru'
|
|
}]
|
|
],
|
|
}
|
|
},
|
|
onLoad() {
|
|
// 检查是否有 token,没有则先登录
|
|
const token = uni.getStorageSync('token');
|
|
|
|
if (!token) {
|
|
// 没有 token,先登录
|
|
this.mini_login().then(() => {
|
|
this.bannerListfn()
|
|
this.$refs.paging && this.$refs.paging.reload()
|
|
}).catch(() => {
|
|
// 登录失败也加载数据(可能是游客模式)
|
|
this.bannerListfn()
|
|
this.$refs.paging && this.$refs.paging.reload()
|
|
})
|
|
} else {
|
|
// 有 token,直接加载数据
|
|
// 如果 token 过期,API 层会自动重新登录
|
|
this.bannerListfn()
|
|
this.$refs.paging && this.$refs.paging.reload()
|
|
}
|
|
},
|
|
onTabItemTap() {
|
|
this.reloadPage()
|
|
},
|
|
onShow() {
|
|
uni.setTabBarItem({
|
|
index: 0,
|
|
text: this.$t('tabbar.home')
|
|
})
|
|
uni.setTabBarItem({
|
|
index:1,
|
|
text: this.$t('tabbar.square')
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 2,
|
|
text: this.$t('tabbar.publish')
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 3,
|
|
text: this.$t('tabbar.mine')
|
|
})
|
|
// if(uni.getStorageSync('token')){
|
|
// this.bannerListfn()
|
|
// this.$refs.paging && this.$refs.paging.reload()
|
|
// }
|
|
},
|
|
methods: {
|
|
async initPage(){
|
|
await this.mini_login()
|
|
await this.bannerListfn()
|
|
},
|
|
reloadPage() {
|
|
this.$refs.paging.reload()
|
|
},
|
|
bannerListfn(){
|
|
request({
|
|
url:'common/banner/list',
|
|
method:'get',
|
|
data:{
|
|
module:'home_module'
|
|
}
|
|
}).then(res => {
|
|
this.bannerList = res.data.data
|
|
})
|
|
},
|
|
// 点击商品项
|
|
navToList(item) {
|
|
uni.navigateTo({
|
|
url: '/pages/square/detiles?id='+item.id
|
|
});
|
|
},
|
|
viewPost(item){
|
|
if(uni.getStorageSync('is_login')){
|
|
}else{
|
|
this.show = true
|
|
}
|
|
},
|
|
cancellang() {
|
|
this.showlang = false
|
|
},
|
|
close(value){
|
|
this[value] = false
|
|
},
|
|
queryList(pageNo, pageSize, from) {
|
|
// 如果是用户下拉刷新(from === 'user-pull-down'),重置为默认时间排序
|
|
if(from === 'user-pull-down' && this.sortField !== ''){
|
|
this.sortField = '';
|
|
this.sortOrder = 'desc';
|
|
}
|
|
|
|
this.loading = true;
|
|
var that = this;
|
|
const params = {
|
|
current:pageNo,
|
|
size:10
|
|
};
|
|
// 添加搜索参数
|
|
if(this.searchTag){
|
|
params.keyword = this.searchTag.replace('#', '');
|
|
} else if(this.searchKeyword){
|
|
params.keyword = this.searchKeyword;
|
|
}
|
|
// 添加排序参数(如果后端支持)
|
|
if(this.sortField){
|
|
params.sort_by = this.sortField;
|
|
params.order = this.sortOrder;
|
|
} else {
|
|
// 默认按时间排序
|
|
params.sort_by = '';
|
|
params.order = 'desc';
|
|
}
|
|
request({
|
|
url:'common/post/list',
|
|
method:'get',
|
|
data: params
|
|
}).then(res => {
|
|
if(res.data.code ==200){
|
|
var datas = res.data.data.records;
|
|
// // 前端排序作为备选方案(如果后端不支持排序参数)
|
|
// if(this.sortField && datas.length > 0){
|
|
// datas = this.sortList(datas);
|
|
// } else if(!this.sortField && datas.length > 0){
|
|
// // 默认按时间排序
|
|
// datas = this.sortListByTime(datas);
|
|
// }
|
|
this.$refs.paging.complete(datas);
|
|
}else{
|
|
// this.$refs.paging.complete(null);
|
|
// that.listlength=0
|
|
}
|
|
uni.stopPullDownRefresh();
|
|
//
|
|
})
|
|
},
|
|
// 处理搜索输入
|
|
handleSearchInput(e) {
|
|
const value = e.detail.value;
|
|
// 检测是否输入了标签格式(#开头)
|
|
if(value.startsWith('#')){
|
|
this.searchTag = value;
|
|
this.searchKeyword = '';
|
|
} else {
|
|
this.searchKeyword = value;
|
|
if(this.searchTag){
|
|
this.searchTag = '';
|
|
}
|
|
}
|
|
},
|
|
// 处理搜索
|
|
handleSearch() {
|
|
if(this.searchKeyword && this.searchKeyword.startsWith('#')){
|
|
this.searchTag = this.searchKeyword;
|
|
this.searchKeyword = '';
|
|
}
|
|
// 重新加载数据
|
|
this.$refs.paging && this.$refs.paging.reload();
|
|
},
|
|
// 移除搜索标签
|
|
removeSearchTag() {
|
|
this.searchTag = '';
|
|
this.searchKeyword = '';
|
|
// 重新加载数据
|
|
this.$refs.paging && this.$refs.paging.reload();
|
|
},
|
|
// 切换排序
|
|
toggleSort(field) {
|
|
if(this.sortField === field){
|
|
// 如果点击的是当前排序字段,切换排序方向
|
|
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
|
|
} else {
|
|
// 如果点击的是新字段,设置为降序
|
|
this.sortField = field;
|
|
this.sortOrder = 'desc';
|
|
}
|
|
// 重新加载数据
|
|
this.$refs.paging && this.$refs.paging.reload();
|
|
},
|
|
// 前端排序(如果后端不支持排序,使用这个)
|
|
sortList(list) {
|
|
const field = this.sortField;
|
|
const order = this.sortOrder;
|
|
return [...list].sort((a, b) => {
|
|
const aVal = a[field] || 0;
|
|
const bVal = b[field] || 0;
|
|
if(order === 'asc'){
|
|
return aVal - bVal;
|
|
} else {
|
|
return bVal - aVal;
|
|
}
|
|
});
|
|
},
|
|
// 按时间排序
|
|
sortListByTime(list) {
|
|
return [...list].sort((a, b) => {
|
|
const aTime = new Date(a.created_at || a.create_time || a.createdAt || 0).getTime();
|
|
const bTime = new Date(b.created_at || b.create_time || b.createdAt || 0).getTime();
|
|
return bTime - aTime; // 降序:最新的在前
|
|
});
|
|
},
|
|
//语言切换事件
|
|
confirmlang(e) {
|
|
var that = this
|
|
this.$i18n.locale = e.value[0].id
|
|
uni.setLocale(e.value[0].id)
|
|
uni.setStorageSync('i18locale', e.value[0].id);
|
|
this.columns =[
|
|
[{
|
|
label: this.$t('zh'),
|
|
id: 'zh'
|
|
}, {
|
|
label: this.$t('en'),
|
|
id: 'en'
|
|
},{
|
|
label: this.$t('ru'),
|
|
id: 'ru'
|
|
}]
|
|
];
|
|
uni.setTabBarItem({
|
|
index: 0,
|
|
text: this.$t('tabbar.square')
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 1,
|
|
text: this.$t('tabbar.publish')
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 2,
|
|
text: this.$t('tabbar.mine')
|
|
})
|
|
this.showlang = false
|
|
var languages = e.value[0].id
|
|
if(e.value[0].id=='zh'){
|
|
languages= 'zh_CN'
|
|
}
|
|
request({
|
|
url:'user/update',
|
|
method:'POST',
|
|
data:{
|
|
language:languages
|
|
}
|
|
}).then(res => {
|
|
uni.showToast({
|
|
title: res.data.message,
|
|
icon: 'none'
|
|
});
|
|
})
|
|
},
|
|
goprivacy(){
|
|
uni.navigateTo({
|
|
url: '/pages/login/agreement',// 替换为你要跳转的页面路径
|
|
});
|
|
},
|
|
gouser(){
|
|
uni.navigateTo({
|
|
url: '/pages/login/agreementuser',// 替换为你要跳转的页面路径
|
|
});
|
|
},
|
|
addCar(){
|
|
if(uni.getStorageSync('is_login')){
|
|
uni.removeStorageSync('draftid')
|
|
uni.removeStorageSync('carinfo')
|
|
uni.navigateTo({
|
|
url: '/pages/carinfo/index'
|
|
});
|
|
}else{
|
|
this.show = true
|
|
}
|
|
},
|
|
selfChangde(e) {
|
|
this.selfChecked = !this.selfChecked;
|
|
},
|
|
loginbtn(){
|
|
if(!this.selfChecked){
|
|
uni.showToast({
|
|
title:this.$t('home.arginimg'),
|
|
icon: 'none'
|
|
});
|
|
return false
|
|
}
|
|
},
|
|
getPhoneNumber(e) {
|
|
let that = this;
|
|
request({
|
|
url:'miniapp/phone',
|
|
method:'POST',
|
|
data:{
|
|
phone_code: e.detail.code,
|
|
}
|
|
}).then(res => {
|
|
if (res.data.code == -1) {
|
|
uni.showToast({
|
|
title: res.data.msg,
|
|
icon: 'none'
|
|
});
|
|
|
|
} else if (res.data.code == 200) {
|
|
//返回数据接收成功
|
|
uni.setStorageSync('is_login', true);
|
|
}
|
|
})
|
|
},
|
|
mini_login() {
|
|
return new Promise((resolve, reject) => {
|
|
uni.login({
|
|
provider: 'weixin',
|
|
success: loginRes => {
|
|
|
|
// 一定要 return,不然 Promise 不会等待
|
|
return request({
|
|
url:'miniapp/login',
|
|
method:'POST',
|
|
data:{ code: loginRes.code }
|
|
}).then(res => {
|
|
|
|
if (res.data.code === 200) {
|
|
|
|
uni.setStorageSync('openid', res.data.data.openid);
|
|
uni.setStorageSync('token', res.data.data.token);
|
|
uni.setStorageSync('user_id', res.data.data.id);
|
|
|
|
if (res.data.data.mobile) {
|
|
uni.setStorageSync('is_login', true);
|
|
} else {
|
|
uni.setStorageSync('is_login', false);
|
|
}
|
|
|
|
resolve(true); // 👍 一定在 Promise 中
|
|
} else {
|
|
uni.showToast({
|
|
title: res.data.msg,
|
|
icon: 'none'
|
|
});
|
|
reject(res);
|
|
}
|
|
})
|
|
},
|
|
fail: (err) => {
|
|
uni.showToast({
|
|
title: '获取 code 失败',
|
|
icon: 'none'
|
|
});
|
|
reject(err); // 👍 必须 reject
|
|
}
|
|
});
|
|
});
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.home-page{
|
|
min-height: 100vh;
|
|
background: #F5F6FA;
|
|
box-sizing: border-box;
|
|
padding-bottom: 120rpx;
|
|
}
|
|
.brand-header{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 20rpx 30rpx;
|
|
background: #F5F6FA;
|
|
}
|
|
.brand-left{
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
.brand-text{
|
|
font-size: 28rpx;
|
|
color: #333;
|
|
margin-right: 10rpx;
|
|
}
|
|
.sun-icon{
|
|
width: 24rpx;
|
|
height: 24rpx;
|
|
background: #FFB800;
|
|
border-radius: 50%;
|
|
}
|
|
.brand-right{
|
|
font-size: 32rpx;
|
|
font-weight: 600;
|
|
color: #3F435B;
|
|
}
|
|
.banner-swiper{
|
|
width: 100%;
|
|
height: 430rpx;
|
|
}
|
|
.banner-img{
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
.banner-desc{
|
|
position: absolute;
|
|
left: 30rpx;
|
|
bottom: 60rpx;
|
|
right: 30rpx;
|
|
}
|
|
.slogan-text{
|
|
display: block;
|
|
font-size: 48rpx;
|
|
font-weight: 600;
|
|
color: #51B6FF;
|
|
text-shadow: 0 2rpx 8rpx rgba(0,0,0,0.2);
|
|
}
|
|
.search{
|
|
padding: 20rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 20rpx;
|
|
background: #fff;
|
|
}
|
|
.search-input-wrapper{
|
|
flex: 1;
|
|
}
|
|
.search-input-box{
|
|
display: flex;
|
|
align-items: center;
|
|
background: #F5F6FA;
|
|
border-radius: 10rpx;
|
|
padding: 15rpx 24rpx;
|
|
gap: 12rpx;
|
|
}
|
|
.search-tag{
|
|
display: flex;
|
|
align-items: center;
|
|
background: #fff;
|
|
border-radius: 20rpx;
|
|
padding: 4rpx 12rpx;
|
|
gap: 8rpx;
|
|
font-size: 24rpx;
|
|
color: #333;
|
|
margin-right: 8rpx;
|
|
flex-shrink: 0;
|
|
}
|
|
.search-tag text{
|
|
font-size: 24rpx;
|
|
color: #333;
|
|
}
|
|
.search-input{
|
|
flex: 1;
|
|
font-size: 28rpx;
|
|
color: #333;
|
|
background: transparent;
|
|
border: none;
|
|
}
|
|
.sort-options{
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 24rpx;
|
|
flex-shrink: 0;
|
|
}
|
|
.sort-item{
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6rpx;
|
|
font-size: 26rpx;
|
|
color: #666;
|
|
cursor: pointer;
|
|
transition: color 0.3s;
|
|
}
|
|
.sort-item.active{
|
|
color: #206ff4;
|
|
font-weight: 500;
|
|
}
|
|
.sort-item text{
|
|
font-size: 26rpx;
|
|
}
|
|
.content-grid{
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
padding: 20rpx;
|
|
justify-content: space-between;
|
|
background: #fff;
|
|
}
|
|
.grid-item{
|
|
width: 48%;
|
|
overflow: hidden;
|
|
margin-bottom: 20rpx;
|
|
}
|
|
.grid-image{
|
|
width: 100%;
|
|
height: 320rpx;
|
|
background: #E5E5E5;
|
|
border-radius: 10rpx;
|
|
}
|
|
.grid-footer{
|
|
padding: 20rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
.grid-avatar{
|
|
width: 48rpx;
|
|
height: 48rpx;
|
|
border-radius: 50%;
|
|
margin-right: 12rpx;
|
|
flex-shrink: 0;
|
|
object-fit: cover;
|
|
display: block;
|
|
}
|
|
.grid-info{
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: 87%;
|
|
}
|
|
.grid-tag{
|
|
font-size: 24rpx;
|
|
color: #3F435B;
|
|
margin-bottom: 4rpx;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
width: 95%;
|
|
}
|
|
.grid-name{
|
|
font-size: 22rpx;
|
|
color: #8A8D97;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
width: 88%;
|
|
}
|
|
.popupcontent{
|
|
background-size: 100% 100%;
|
|
padding: 26px 15px;
|
|
text-align: center;
|
|
background-repeat: no-repeat;
|
|
.title{
|
|
color: #333333;
|
|
font-size: 15px;
|
|
margin-bottom: 15px;
|
|
}
|
|
}
|
|
.log1{
|
|
width: 180px;
|
|
height: 180px;
|
|
}
|
|
.yhxy{
|
|
color: #999999;
|
|
font-size: 12px;
|
|
margin-bottom: 5px;
|
|
.xy{
|
|
color: #297EFF;
|
|
}
|
|
}
|
|
.cent{
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-around;
|
|
padding: 0px 10px 20px;
|
|
.btn1{
|
|
background-color: #fff;
|
|
border: 1px solid #206ff4;
|
|
color: #206ff4;
|
|
border-radius: 50px;
|
|
width: 46%;
|
|
margin: 10px 0px 20px;
|
|
height: 50px;
|
|
line-height: 50px;
|
|
}
|
|
.btn{
|
|
background-color: #206ff4;
|
|
color: white;
|
|
border-radius: 50px;
|
|
width: 46%;
|
|
margin: 10px 0px 20px;
|
|
height: 50px;
|
|
line-height: 50px;
|
|
}
|
|
}
|
|
</style> |