359 lines
7.8 KiB
Vue
359 lines
7.8 KiB
Vue
<template>
|
|
<view class="page">
|
|
<z-paging ref="paging" :auto="false" v-model="list" @query="queryList" empty-view-text="暂无数据!">
|
|
<!-- 顶部背景 -->
|
|
<view class="header">
|
|
<image src="/static/image/homebg.png" mode="aspectFill" class="bg"></image>
|
|
|
|
<!-- 弹幕组件 -->
|
|
<danmu :list="danmuList" :row="5" :visible="danmuVisible"></danmu>
|
|
|
|
<!-- 标题 -->
|
|
<view class="title">
|
|
<view>西门子样机</view>
|
|
<view>福利平台</view>
|
|
</view>
|
|
|
|
<!-- 右侧按钮 -->
|
|
<view class="right-btns">
|
|
<view class="circle-btn" :class="{ active: danmuVisible }" @click="toggleDanmu">
|
|
<image v-if="danmuVisible" src="/static/image/dan1.png" mode=""></image>
|
|
<image v-else src="/static/image/danm.png" mode=""></image>
|
|
</view>
|
|
<button open-type="share" class="circle-btn">
|
|
<image src="/static/image/shares.png" class="share" mode=""></image>
|
|
</button>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 主体内容 -->
|
|
|
|
<view class="main-box">
|
|
<view class="titles">
|
|
样机广场
|
|
</view>
|
|
<view class="tabs">
|
|
<view :class="['tab',activeTab==0?'on':'']" @tap="tabclick(0)">
|
|
<text>最新发布</text>
|
|
</view>
|
|
<view class="divider"></view>
|
|
<view :class="['tab',activeTab==1?'on':'']" @tap="tabclick(1)">
|
|
<text>距离最近</text>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 用户卡片 -->
|
|
<view class="card">
|
|
<post-card
|
|
v-for="sitem in list"
|
|
:key="sitem.id || sitem.username"
|
|
:item="sitem"
|
|
@userClick="goto"
|
|
@view="goto"
|
|
@contact="handleContact"
|
|
@comment="handleComment">
|
|
</post-card>
|
|
</view>
|
|
|
|
</view>
|
|
</z-paging>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import danmu from '@/components/danmu/danmu.vue';
|
|
import PostCard from '@/components/PostCard.vue'
|
|
import { request,showToast } from '@/api/apiT.js'
|
|
export default {
|
|
components: { danmu, PostCard },
|
|
data() {
|
|
return {
|
|
activeTab: 0,
|
|
danmuVisible:true,
|
|
content:'',
|
|
list:[],
|
|
danmuList: [],
|
|
latitude:'',
|
|
longitude:''
|
|
};
|
|
},
|
|
onLoad() {
|
|
// 数据加载逻辑
|
|
if (!uni.getStorageSync('token')) {
|
|
this.mini_login().then(() => {
|
|
this.barragelist()
|
|
this.$refs.paging && this.$refs.paging.reload()
|
|
})
|
|
}else{
|
|
this.barragelist()
|
|
this.$refs.paging && this.$refs.paging.reload()
|
|
}
|
|
},
|
|
onShow() {
|
|
this.getFuzzy().then(res => {
|
|
this.latitude = res.latitude
|
|
this.longitude = res.longitude
|
|
console.log(res);
|
|
}).catch(err => console.error(err));
|
|
},
|
|
methods: {
|
|
getFuzzy() {
|
|
return new Promise((resolve, reject) => {
|
|
wx.getSetting({
|
|
success: (st) => {
|
|
const ok = st.authSetting['scope.userFuzzyLocation'];
|
|
const run = () => wx.getFuzzyLocation({
|
|
type: 'wgs84',
|
|
success: resolve,
|
|
fail: reject
|
|
});
|
|
|
|
if (ok) return run();
|
|
|
|
wx.authorize({
|
|
scope: 'scope.userFuzzyLocation',
|
|
success: run,
|
|
fail: () => wx.openSetting({ success: () => reject(new Error('未授权')) })
|
|
});
|
|
},
|
|
fail: reject
|
|
});
|
|
});
|
|
},
|
|
tabclick(item){
|
|
this.activeTab = item;
|
|
this.$refs.paging && this.$refs.paging.reload()
|
|
},
|
|
//获取弹幕
|
|
barragelist(){
|
|
request({
|
|
url: 'admin/barrage/list',
|
|
method: 'GET',
|
|
}).then(res => {
|
|
if (res.data.code === 200) {
|
|
this.danmuList = res.data.data.records
|
|
}
|
|
})
|
|
},
|
|
toggleDanmu() {
|
|
this.danmuVisible = !this.danmuVisible;
|
|
},
|
|
goto(item){
|
|
uni.navigateTo({
|
|
url: '/pages/square/detiles?id='+item.id
|
|
});
|
|
},
|
|
handleContact(item) {
|
|
const phone = item.user.mobile
|
|
if (!phone) return uni.showToast({ title: '号码为空', icon: 'none' });
|
|
// 简单清洗:去空格/横杠
|
|
const num = String(phone).replace(/[^\d+]/g, '');
|
|
uni.makePhoneCall({ phoneNumber: num });
|
|
},
|
|
handleComment(item) {
|
|
uni.navigateTo({
|
|
url: '/pages/square/detiles?id=' + (item?.id || 1)
|
|
});
|
|
},
|
|
queryList(pageNo, pageSize, from) {
|
|
this.loading = true;
|
|
var that = this;
|
|
const params = {
|
|
current:pageNo,
|
|
status:1,
|
|
size:10
|
|
};
|
|
const collectUrl = this.activeTab==0 ? 'common/post/list' : 'common/post/nearby'
|
|
// 添加排序参数(如果后端支持)
|
|
if(this.activeTab==1){
|
|
params.lng = this.longitude;
|
|
params.lat = this.latitude;
|
|
} else {
|
|
}
|
|
request({
|
|
url:collectUrl,
|
|
method:'get',
|
|
data: params
|
|
}).then(res => {
|
|
if(res.data.code ==200){
|
|
var datas = res.data.data.records;
|
|
this.$refs.paging.complete(datas);
|
|
}else{
|
|
}
|
|
uni.stopPullDownRefresh();
|
|
//
|
|
})
|
|
},
|
|
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);
|
|
|
|
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
|
|
}
|
|
});
|
|
});
|
|
}
|
|
},
|
|
// 分享给好友
|
|
onShareAppMessage() {
|
|
return {
|
|
title: '西门子样机福利平台',
|
|
path: '/pages/index/index?from=share',
|
|
imageUrl: "/static/image/share.jpg" // 封面图
|
|
}
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.page {
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.header {
|
|
position: relative;
|
|
height: 720rpx;
|
|
}
|
|
.bg {
|
|
width: 100%;
|
|
height: 100%;
|
|
border-bottom-left-radius: 30rpx;
|
|
border-bottom-right-radius: 30rpx;
|
|
}
|
|
|
|
.title {
|
|
position: absolute;
|
|
left: 40rpx;
|
|
top: 300rpx;
|
|
font-size: 68rpx;
|
|
line-height: 1.2;
|
|
color: #fff;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.right-btns {
|
|
position: absolute;
|
|
right: 40rpx;
|
|
bottom: 100rpx;
|
|
|
|
.circle-btn {
|
|
margin-top: 20rpx;
|
|
width: 80rpx;
|
|
height: 80rpx;
|
|
border-radius: 50%;
|
|
background: #fff;
|
|
padding: 4rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
image{
|
|
width: 60rpx;
|
|
height: 60rpx;
|
|
}
|
|
.share{
|
|
width: 36rpx;
|
|
height: 36rpx;
|
|
}
|
|
}
|
|
}
|
|
/* 激活状态(弹幕开启) */
|
|
.circle-btn.active {
|
|
background: #00c28a;
|
|
color: #fff;
|
|
}
|
|
.main-box {
|
|
margin: 20rpx 30rpx;
|
|
margin-top: -60rpx;
|
|
position: relative;
|
|
background: #fff;
|
|
border-radius: 30rpx;
|
|
.titles{
|
|
font-size: 34rpx;
|
|
text-align: center;
|
|
color: #000;
|
|
font-weight: bold;
|
|
line-height: 88rpx;
|
|
}
|
|
}
|
|
|
|
.tabs {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-around;
|
|
gap: 20rpx;
|
|
margin-bottom: 30rpx;
|
|
|
|
.tab {
|
|
position: relative;
|
|
padding: 12rpx 24rpx;
|
|
font-size: 28rpx;
|
|
color: #000;
|
|
}
|
|
.tab::after {
|
|
content: '';
|
|
position: absolute;
|
|
left: 50%;
|
|
bottom: -10rpx;
|
|
width: 60rpx;
|
|
height: 4rpx;
|
|
background: #3BC6BD;
|
|
border-radius: 4rpx;
|
|
transform: translateX(-50%);
|
|
opacity: 0;
|
|
transition: opacity 0.2s;
|
|
}
|
|
.tab.on {
|
|
color: #3BC6BD;
|
|
font-weight: 600;
|
|
}
|
|
.tab.on::after {
|
|
opacity: 1;
|
|
}
|
|
|
|
.divider {
|
|
width: 1px;
|
|
height: 24rpx;
|
|
background: #dcdcdc;
|
|
}
|
|
}
|
|
|
|
.card {
|
|
padding: 10rpx;
|
|
}
|
|
</style>
|