This commit is contained in:
浅念
2025-12-03 14:07:17 +08:00
commit 087514270a
857 changed files with 104338 additions and 0 deletions
+164
View File
@@ -0,0 +1,164 @@
<template>
<view>
<uni-nav-bar leftText=" " :fixed="true" :border="false" leftIcon="back" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" :title="$t('navbar.changinfo')"></uni-nav-bar>
<view class="content">
<view class="cell">
<view>{{$t('mine.avatar')}}</view>
<view class="right">
<uni-file-picker fileMediatype="image" limit="1" @select="select" @delete="delfn" :del-icon="false" disable-preview :imageStyles="imageStyles">
<image :src="userinfo.avatar_pull==''?'/static/image/mine/user.png':userinfo.avatar_pull" mode="" class="addimg"></image>
</uni-file-picker>
</view>
</view>
<view class="cell1">
<view>{{$t('mine.nickname')}}</view>
<view class="right select">
<input :placeholder="$t('mine.nickinput')" v-model="userinfo.nickname"></input>
<uni-icons type="right" size="18"></uni-icons>
</view>
</view>
</view>
<view class="foot">
<button class="btn" @click="bcFn">{{$t('button.save')}}</button>
</view>
</view>
</template>
<script>
import { request,showToast } from '@/api/apiT.js'
export default {
data() {
return {
imageStyles: {
width: 40,
height: 40,
border: {
radius: '50%'
}
},
userinfo:{
nickname:'',
avatar:'',
company:'',
phone:'',
},
}
},
onLoad() {
this.getinfo()
},
methods: {
getinfo(){
var that= this;
request({
url:'common/user/info',
method:'POST',
}).then(res => {
this.userinfo=res.data.data.user
})
},
uploadfn(imgUrl){
var that = this;
uni.uploadFile({
url: 'https://bsh.info.hb.hnzhwlkj.cn/upload/image?scene=userinfo',
filePath: imgUrl,
name: 'image',
header:{'content-type': 'application/x-www-form-urlencoded','Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),'Fdesk-Language': uni.getStorageSync('i18locale')?uni.getStorageSync('i18locale'):'zh','Fdesk-Login-Type': 'wechat','Fdesk-System-Code':'wechat'},
success: (uploadFileRes) => {
const path=JSON.parse(uploadFileRes.data)
that.userinfo.avatar = path.data.href
}
});
},
delfn(){
that.userinfo.avatar =''
},
select(e){
const tempFilePaths = e.tempFilePaths;
const imgUrl=tempFilePaths[0]
this.uploadfn(imgUrl)
},
leftClick(){
uni.navigateBack({})
},
bcFn(){
request({
url:'common/user/update',
method:'POST',
data:{
nickname:this.userinfo.nickname,
avatar:this.userinfo.avatar
}
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code ==200){
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/mine',// 替换为你要跳转的页面路径
});
}, 1000);
}
})
}
}
}
</script>
<style>
.uniui-right{
position: absolute;
top: 2px;
}
.content{
margin: 20px 12px;
background: #FFFFFF;
border-radius: 10px;
}
.cell{
display: flex;
justify-content:space-between;
padding: 10px 20px;
/* border-bottom: 1px solid #C3C3C3; */
align-items: center;
font-weight: 500;
}
.cell1{
display: flex;
justify-content:space-between;
padding: 18px 20px;
align-items: center;
font-weight: 500;
}
.right{
text-align: right;
}
.select{
display: flex;
position: relative;
margin-right: 10px;
}
.foot{
position: fixed;
bottom: 0px;
width: 100%;
height: 240rpx;
background: #FFFFFF;
}
.btn{
background: linear-gradient(180deg, #206ff4 0%, #42e0a2 100%);
color: white;
border-radius: 50px;
width: 84%;
margin-bottom: 40px;
margin: 20px 8%;
}
.addimg{
width: 35px;
height: 35px;
border-radius: 50%;
}
</style>
+407
View File
@@ -0,0 +1,407 @@
<template>
<view class="content">
<uni-nav-bar leftText=" " :fixed="true" :border="false" leftIcon="back" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" title="我的发布"></uni-nav-bar>
<view class="year-selector" @click="showYearPicker">
<text class="year-text">{{selectedYear}}年</text>
<uni-icons type="arrowdown" size="14" color="#666"></uni-icons>
</view>
<scroll-view scroll-y class="scroll-container"
refresher-enabled
:refresher-triggered="refreshing"
@refresherrefresh="onRefresh"
:lower-threshold="100"
@scrolltolower="onLoadMore">
<view class="post-list">
<view v-for="(group, dateKey) in groupedPosts" :key="dateKey" class="date-group">
<view class="date-item">
<view class="date-label">
<text class="date-day">{{group.day}}</text>
<text class="date-month">{{group.month}}月</text>
</view>
<view class="posts-container">
<view v-for="post in group.posts" :key="post.id" class="post-item" @click="viewPost(post)">
<image class="post-image" :src="post.media && post.media[0] ? post.media[0].url_pull : '/static/image/placeholder.png'" mode="aspectFill"></image>
<text class="post-tag">{{post.content || ''}}</text>
</view>
</view>
</view>
</view>
<!-- 加载更多提示 -->
<view v-if="hasMore && postList.length > 0" class="load-more">
<text v-if="loadingMore">加载中...</text>
<text v-else>上拉加载更多</text>
</view>
<view v-else-if="!hasMore && postList.length > 0" class="load-more">
<text>没有更多了</text>
</view>
<view v-if="postList.length === 0 && !loading && !loadingMore" class="empty-view">
<text>暂无发布内容</text>
</view>
</view>
</scroll-view>
<!-- 年份选择器 -->
<u-picker
:show="showYearSelect"
:columns="yearColumns"
:defaultIndex="defaultYearIndex"
keyName="label"
@confirm="onYearConfirm"
@cancel="showYearSelect = false"
title="选择年份">
</u-picker>
<!-- 加载提示 -->
<view v-if="loading" class="loading-mask">
<view class="loading-text">加载中...</view>
</view>
</view>
</template>
<script>
import { request } from '@/api/apiT.js'
export default {
data() {
// 生成年份列表(当前年份前后5年)
const currentYear = new Date().getFullYear();
const years = [];
for (let i = currentYear - 5; i <= currentYear + 5; i++) {
years.push({ label: i.toString(), value: i });
}
return {
selectedYear: currentYear,
showYearSelect: false,
yearColumns: [years],
postList: [],
groupedPosts: {},
loading: false,
refreshing: false,
loadingMore: false, // 上拉加载状态
page: 1, // 当前页码
pageSize: 10, // 每页数量
hasMore: true, // 是否还有更多数据
total: 0, // 总数据量
}
},
computed: {
// 计算当前年份在选择器中的默认索引
defaultYearIndex() {
const currentYear = new Date().getFullYear();
const startYear = currentYear - 5;
return [currentYear - startYear]; // 当前年份在数组中的索引
}
},
onLoad() {
this.loadPostList();
},
methods: {
leftClick() {
// uni.navigateBack()
uni.reLaunch({
url: '/pages/index/mine',// 替换为你要跳转的页面路径
});
},
showYearPicker() {
this.showYearSelect = true;
},
onYearConfirm(e) {
if (e.value && e.value[0]) {
const selectedItem = typeof e.value[0] === 'object' ? e.value[0] : { value: e.value[0], label: e.value[0].toString() };
this.selectedYear = selectedItem.value || parseInt(selectedItem.label);
this.showYearSelect = false;
// 切换年份时重置分页
this.page = 1;
this.hasMore = true;
this.postList = [];
this.groupedPosts = {};
this.loadPostList(false);
}
},
// 加载帖子列表
loadPostList(isLoadMore = false) {
// 防止重复请求
if (isLoadMore) {
if (this.loadingMore || this.loading || this.refreshing || !this.hasMore) {
return;
}
this.loadingMore = true;
this.page += 1;
} else {
if (this.loading && !this.refreshing) {
return;
}
this.loading = true;
this.page = 1;
this.hasMore = true;
if (!isLoadMore && !this.refreshing) {
this.postList = [];
this.groupedPosts = {};
}
}
// 获取当前用户发布的帖子列表
request({
url: 'common/post/list',
method: 'GET',
data: {
// 只获取当前用户发布的帖子,后端应该根据token自动过滤
current: this.page,
size: this.pageSize,
scene:'self',
year:this.selectedYear
}
}).then(res => {
this.loading = false;
this.loadingMore = false;
this.refreshing = false;
if (res.data.code == 200) {
const records = res.data.data.records || [];
const total = res.data.data.total || 0;
this.total = total;
// 过滤出当前年份的数据
const yearFilteredRecords = records.filter(post => {
if (!post.created_at) return false;
const dateStr = post.created_at;
const postYear = new Date(dateStr).getFullYear();
return postYear === this.selectedYear;
});
if (isLoadMore) {
// 上拉加载更多,追加数据并去重
const existingIds = new Set(this.postList.map(item => item.id));
const newRecords = yearFilteredRecords.filter(item => !existingIds.has(item.id));
this.postList = [...this.postList, ...newRecords];
} else {
// 下拉刷新或初次加载,替换数据
this.postList = yearFilteredRecords;
}
// 重新分组
this.groupPostsByDate();
// 判断是否还有更多数据
// 如果当前页返回的原始数据少于pageSize,说明没有更多了
// 或者已经加载到最后一页
if (records.length < this.pageSize) {
this.hasMore = false;
} else {
// 计算理论上最多能加载多少页
const maxPages = Math.ceil(total / this.pageSize);
this.hasMore = this.page < maxPages;
}
}
}).catch(() => {
this.loading = false;
this.loadingMore = false;
this.refreshing = false;
if (isLoadMore) {
this.page -= 1; // 加载失败,页码回退
}
});
},
// 按日期分组帖子
groupPostsByDate() {
const grouped = {};
this.postList.forEach(post => {
const dateStr = post.created_at || post.create_time || post.createdAt;
if (!dateStr) return;
const date = new Date(dateStr);
const month = date.getMonth() + 1; // 月份从0开始,需要+1
const day = date.getDate();
// 生成日期key,格式:MM-DD,用于排序
const dateKey = `${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
if (!grouped[dateKey]) {
grouped[dateKey] = {
day: day,
month: month,
posts: []
};
}
grouped[dateKey].posts.push(post);
});
// 按日期倒序排序(最新的在前)
const sortedKeys = Object.keys(grouped).sort((a, b) => {
// 按完整日期排序(年-月-日)
const dateA = new Date(this.selectedYear, parseInt(a.split('-')[0]) - 1, parseInt(a.split('-')[1]));
const dateB = new Date(this.selectedYear, parseInt(b.split('-')[0]) - 1, parseInt(b.split('-')[1]));
return dateB - dateA; // 倒序:最新的在前
});
// 重新构建分组对象,保持顺序
const sortedGrouped = {};
sortedKeys.forEach(key => {
sortedGrouped[key] = grouped[key];
});
this.groupedPosts = sortedGrouped;
},
// 下拉刷新
onRefresh() {
// 如果正在加载中,不执行刷新
if (this.loading || this.loadingMore) {
this.refreshing = false;
return;
}
this.refreshing = true;
this.page = 1;
this.hasMore = true;
this.loadPostList(false);
},
// 上拉加载更多
onLoadMore() {
if (!this.hasMore || this.loadingMore || this.loading || this.refreshing) {
return;
}
this.loadPostList(true);
},
// 查看帖子详情
viewPost(post) {
// TODO: 跳转到帖子详情页
uni.navigateTo({
url: '/pages/square/detiles?id='+post.id
});
}
}
}
</script>
<style lang="scss">
page,
.content {
height: 100%;
background-color: #fff;
}
.year-selector {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 30rpx;
background-color: #F5F5F5;
.year-text {
font-size: 28rpx;
color: #333;
}
.arrow-icon {
width: 24rpx;
height: 24rpx;
}
}
.scroll-container {
height: calc(100% - 168rpx); // 减去导航栏和年份选择器高度
}
.post-list {
padding: 20rpx 0;
}
.date-group {
margin-bottom: 40rpx;
}
.date-item {
display: flex;
padding: 0 30rpx;
}
.date-label {
display: flex;
// flex-direction: column;
// align-items: center;
margin-right: 30rpx;
min-width: 120rpx;
.date-day {
font-size: 48rpx;
font-weight: bold;
color: #333;
line-height: 1;
}
.date-month {
font-size: 24rpx;
color: #666;
margin-top: 8rpx;
}
}
.posts-container {
flex: 1;
display: flex;
flex-direction: column;
gap: 20rpx;
}
.post-item {
display: flex;
// align-items: center;
margin-bottom: 30rpx;
.post-image {
width: 200rpx;
height: 200rpx;
background-color: #E5E5E5;
border-radius: 10rpx;
margin-right: 30rpx;
flex-shrink: 0;
}
.post-tag {
font-size: 28rpx;
color: #333;
flex: 1;
}
}
.empty-view {
text-align: center;
padding: 100rpx 0;
color: #999;
font-size: 28rpx;
}
.load-more {
width: 100%;
text-align: center;
padding: 30rpx 0;
font-size: 26rpx;
color: #999;
}
.loading-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.3);
display: flex;
align-items: center;
justify-content: center;
z-index: 999;
.loading-text {
color: #fff;
font-size: 28rpx;
background-color: rgba(0, 0, 0, 0.7);
padding: 20rpx 40rpx;
border-radius: 8rpx;
}
}
</style>
+125
View File
@@ -0,0 +1,125 @@
<template>
<view class="home-page">
<z-paging ref="paging" v-model="contList" @query="queryList" empty-view-text="暂无消息">
<template #top>
<uni-nav-bar leftText=" " :fixed="true" :border="false" leftIcon="back" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" title="最新消息"></uni-nav-bar>
</template>
<view class="msg-list">
<view class="msg-item" v-for="item in contList" :key="item.id">
<image class="msg-avatar" :src="item.sender_user.avatar_pull" mode="aspectFill"></image>
<view class="msg-body">
<view class="msg-header">
<text class="msg-name">{{item.sender_user.nickname}}</text>
<text class="msg-time">{{item.created_at}}</text>
</view>
<text class="msg-text">
<text>{{ item.type==1?'点赞了': item.type==2?'收藏了':'评论了' }} </text>
<text>{{ formatContent(item.post && item.post.content) }}</text>
</text>
</view>
</view>
</view>
</z-paging>
</view>
</template>
<script>
import { request } from '@/api/apiT.js'
export default {
data() {
return {
contList: [],
defaultAvatar: '/static/image/mine/user.png'
}
},
methods: {
leftClick(){
uni.navigateBack({})
},
queryList(pageNo, pageSize) {
request({
url:'common/post/messageNotice/list',
method:'get',
data: {
current:pageNo,
size:pageSize || 10
}
}).then(res => {
if(res.data.code === 200){
const datas = res.data.data.records || [];
this.$refs.paging.complete(datas);
}else{
this.$refs.paging.complete(false);
uni.showToast({
title:res.data.message || '加载失败',
icon:'none'
});
}
uni.stopPullDownRefresh();
}).catch(() => {
this.$refs.paging.complete(false);
})
},
formatContent(content){
if(!content) return '';
const text = content.trim();
return text.length > 10 ? `${text.slice(0,10)}...` : text;
}
}
}
</script>
<style lang="scss">
.home-page{
min-height: 100vh;
background: #F5F6FA;
box-sizing: border-box;
padding-bottom: 120rpx;
}
.msg-list{
padding: 20rpx;
}
.msg-item{
display: flex;
align-items: center;
padding: 24rpx 20rpx;
margin-bottom: 20rpx;
border-bottom: 1px solid #e4e4e4;
}
.msg-avatar{
width: 96rpx;
height: 96rpx;
border-radius: 50%;
margin-right: 20rpx;
}
.msg-body{
flex: 1;
display: flex;
flex-direction: column;
width: 80%;
}
.msg-header{
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10rpx;
}
.msg-name{
font-size: 26rpx;
font-weight: 600;
color: #333;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 40%;
}
.msg-time{
font-size: 24rpx;
color: #999;
}
.msg-text{
font-size: 24rpx;
color: #666;
line-height: 38rpx;
}
</style>
+154
View File
@@ -0,0 +1,154 @@
<template>
<view class="home-page">
<z-paging ref="paging" :auto="false" v-model="contList" @query="queryList" empty-view-text="暂无数据!">
<template #top>
<uni-nav-bar leftText=" " :fixed="true" :border="false" leftIcon="back" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" title="我的收藏"></uni-nav-bar>
</template>
<!-- 内容网格 -->
<view class="content-grid">
<square-post-card
class="grid-item"
v-for="sitem in contList"
:key="sitem.id"
:item="sitem.post"
:isshow="false"
@view="navToList"
@comment="viewPost"
@like="viewPost" />
</view>
</z-paging>
</view>
</template>
<script>
import { request,showToast } from '@/api/apiT.js'
import SquarePostCard from '@/components/SquarePostCard.vue'
export default {
components: {
SquarePostCard
},
data() {
return {
contList:[]
}
},
onLoad() {
},
onShow(){
this.$refs.paging.reload()
},
methods: {
leftClick(){
uni.reLaunch({
url: '/pages/index/mine',// 替换为你要跳转的页面路径
});
// uni.navigateBack({})
},
// 点击商品项
navToList(item) {
uni.navigateTo({
url: '/pages/square/detiles?id='+item.id
});
},
queryList(pageNo, pageSize) {
this.loading = true;
var that = this;
request({
url:'common/post/favorite/self',
method:'get',
data: {
current:pageNo,
size:10
}
}).then(res => {
if(res.data.code ==200){
var datas = res.data.data.records;
this.$refs.paging.complete(datas);
}else{
// this.$refs.paging.complete(null);
// that.listlength=0
}
uni.stopPullDownRefresh();
//
})
},
}
}
</script>
<style>
.home-page{
min-height: 100vh;
background: #F5F6FA;
box-sizing: border-box;
padding-bottom: 120rpx;
}
.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%;
}
.iconview{
margin-right: 10px;
display: inline-block;
font-size: 22rpx;
}
.icons {
width: 16px;
height: 16px;
margin-right: 5px;
}
</style>