Files
yusheng-h5/pages/union/index.vue

541 lines
12 KiB
Vue
Raw Normal View History

2025-08-11 11:06:07 +08:00
<template>
2025-10-23 16:04:28 +08:00
<view class="view-page" :style="{backgroundImage: `url('${ThemeData?.app_bg || baseBgUrl}')`}">
2025-08-11 11:06:07 +08:00
<navBar :style="{marginTop: `${statusBarHeight}${uni.getSystemInfoSync().platform === 'ios' ? 'px': 'dp'}`}"
:navTitle="'公会中心'" :emitBack="true" @backEvent="back">
<template #rightView>
2025-10-23 16:04:28 +08:00
<view v-if="isMerber" @click="jumpMineUnion" class="font-24 minUnicon" style="white-space: nowrap">
2025-08-11 11:06:07 +08:00
我的公会
</view>
</template>
</navBar>
<view class="content">
<view class="flex-input">
<uni-easyinput type="number" prefixIcon="search" clearSize="18" v-model="searchValue"
placeholder="请输入公会ID">
</uni-easyinput>
<view class="search-button" @click="search">
搜索
</view>
</view>
2025-10-23 16:04:28 +08:00
<swiper class="swipe-view" circular :autoplay="true" :interval="2000" :duration="500">
<swiper-item v-for="item in swiperList" :key="item">
<view class="swiper-item uni-bg-red">
<img :src="item.image" alt="" />
</view>
</swiper-item>
</swiper>
2025-08-11 11:06:07 +08:00
<view class="title">
热门公会
</view>
<view class="hotspot-view">
<view class="hotspot-box" v-for="data in listData" :key="data.id" @click="viewDetails(data)">
<view class="flex-line">
<view class="head-portrait">
<img :src="data.cover || logo" alt="" />
</view>
<view class="info-box ml-20">
<view class="flex-line">
<span class="truncate">{{data.guild_name}}</span><span
class="id-title">ID:{{data.guild_special_id}}</span>
<img @click.stop="copyData(data.guild_special_id)" class="icon-box"
src="@/static/image/union/copy.png" alt="" />
</view>
<view class="subhead-title truncate">
{{data.intro}}
</view>
<view class="chairman">
<view class="chairman-portrait">
<img :src="data.user_avatar" alt="暂无头像" />
</view>
2025-10-23 16:04:28 +08:00
<view class="chairman-name">
2025-08-11 11:06:07 +08:00
{{data.user_name}}
</view>
</view>
</view>
</view>
<view class="right-button">
2025-10-23 16:04:28 +08:00
<!-- <view class="apply-button">
申请
</view> -->
<view class="online-view">
<view v-show="data.guild_user_list.length">
<view class="avatars-container">
<view class="avatar" v-for="ele in data.guild_user_list.slice(0,3)" :key="ele.id">
<img :src="ele.avatar" alt="" />
</view>
2025-08-11 11:06:07 +08:00
</view>
2025-10-23 16:04:28 +08:00
</view>
<view class="online-people">
2025-08-11 11:06:07 +08:00
{{data.num}}
</view>
</view>
</view>
</view>
<uni-load-more :status="loading ? 'loading' : noMore ? 'noMore' : 'more'" />
</view>
</view>
</view>
</template>
<script>
import navBar from '@/component/nav.vue';
import http from '@/until/http.js';
import logo from '@/static/image/logo.png';
2025-10-23 16:04:28 +08:00
import baseBgUrl from '@/static/image/general/fy_bg.jpg';
2025-08-11 11:06:07 +08:00
export default {
components: {
navBar
},
data() {
return {
searchValue: '',
2025-10-23 16:04:28 +08:00
baseBgUrl,
2025-08-11 11:06:07 +08:00
logo,
loading: false,
noMore: false,
pageConfig: {
pageSize: 5,
currentPage: 1,
total: 2
},
isMerber: null,
listData: [],
UnionByUser: null,
2025-08-13 10:39:47 +08:00
statusBarHeight: 0,
2025-10-23 16:04:28 +08:00
ThemeData: null,
swiperList: []
2025-08-11 11:06:07 +08:00
}
},
onLoad(options) {
const {
id,
h
} = options
2025-10-23 16:04:28 +08:00
uni.setStorageSync('token', id || '')
2025-08-11 11:06:07 +08:00
if (uni.getStorageSync('token')) {
this.getList()
this.getInfo()
2025-10-23 16:04:28 +08:00
this.getSwiper()
2025-08-11 11:06:07 +08:00
}
this.statusBarHeight = h
uni.setStorageSync('BarHeight', h)
2025-10-23 16:04:28 +08:00
if (uni.getStorageSync('Theme_Data')) {
2025-08-13 10:39:47 +08:00
this.ThemeData = JSON.parse(uni.getStorageSync('Theme_Data'))
}
2025-10-23 16:04:28 +08:00
// 监听事件,事件名如 'refreshList'
uni.$on('refreshList', (data) => {
this.refreshList(); // 执行刷新方法
// 如果传递了数据,可以从 data 中获取
});
},
onUnload() {
// 页面卸载时移除事件监听,避免内存泄漏和重复监听
uni.$off('refreshList');
2025-08-11 11:06:07 +08:00
},
onReachBottom() {
if (!this.loading && !this.noMore) {
this.getList()
}
},
methods: {
// 关闭当前公会中心页面
back() {
this.closeWeb()
},
search() {
this.pageConfig.currentPage = 1
this.listData = []
this.getList()
},
2025-10-23 16:04:28 +08:00
refreshList() {
this.searchValue = ''
this.search()
this.getInfo()
},
2025-08-11 11:06:07 +08:00
closeWeb() {
const platform = uni.getSystemInfoSync().platform;
// console.log(platform, '打印设备参数')
if (platform === 'ios') {
console.log('调用iOS原生方法')
// 通过 messageHandlers 调用 iOS 原生方法
window.webkit.messageHandlers.nativeHandler.postMessage({
'action': 'closeWeb'
});
} else if (platform === 'android') {
console.log('调用Android原生方法')
// 调用 Android 原生方法
window.Android.closeWeb();
}
},
2025-10-23 16:04:28 +08:00
async getSwiper() {
http.get('/api/banner/get_banner_list', {
token: uni.getStorageSync('token') || '',
show_type: 5
}).then(response => {
const {
data,
code
} = response
this.swiperList = code ? data : []
})
},
2025-08-11 11:06:07 +08:00
async getInfo() {
http.get('/api/Guild/is_guild_member', {
2025-10-23 16:04:28 +08:00
token: uni.getStorageSync('token') || ''
2025-08-11 11:06:07 +08:00
}).then(response => {
const {
data,
code
} = response
this.isMerber = code ? data : false
this.UnionByUser = code ? data.guild_id : 0
}).catch(error => {
this.isMerber = false
this.UnionByUser = null
});
},
async getList() {
this.loading = true
http.get('/api/Guild/guild_list', {
page: this.pageConfig.currentPage,
limit: this.pageConfig.pageSize,
search_id: this.searchValue,
2025-10-23 16:04:28 +08:00
token: uni.getStorageSync('token') || ''
2025-08-11 11:06:07 +08:00
}).then(response => {
const {
data,
code
} = response
if (code) {
this.pageConfig.total = data.count
this.loading = false
const newData = data.list || []
if (newData.length === 0) {
this.noMore = true
return
}
this.listData = [...this.listData, ...newData]
this.pageConfig.currentPage++
if (this.listData.length === this.pageConfig.total) {
this.noMore = true
return
}
}
}).catch(error => {
this.loading = false
});
},
// 点击公会详情
viewDetails(data) {
uni.navigateTo({
url: `/pages/union/detail?id=${data.id}`
});
},
// 跳转到我的公会
jumpMineUnion() {
uni.navigateTo({
url: `/pages/union/detail?id=${this.UnionByUser}`
});
},
copyData(text) {
2025-10-23 16:04:28 +08:00
if (text) {
2025-08-11 11:06:07 +08:00
if (uni.getSystemInfoSync().platform === 'h5') {
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
2025-10-23 16:04:28 +08:00
2025-08-11 11:06:07 +08:00
uni.showToast({
title: '复制成功',
icon: 'none',
});
return;
} else {
uni.setClipboardData({
data: text,
success: () => {
uni.showToast({
title: '已复制到剪贴板',
icon: 'none',
duration: 1500
});
},
fail: () => {
uni.showToast({
title: '复制失败,请重试',
icon: 'none'
});
}
});
}
} else {
uni.showToast({
title: '暂无可复制文本',
icon: 'none'
});
}
}
}
}
</script>
2025-10-23 16:04:28 +08:00
<style lang="scss" scoped>
2025-08-11 11:06:07 +08:00
.view-page {
// padding: 32rpx;
// min-height: 100vh;
min-height: 100vh;
font-family: Source Han Sans CN, Source Han Sans CN;
2025-08-13 10:39:47 +08:00
// background-image: url('@/static/image/help/bg.png');
2025-08-11 11:06:07 +08:00
background-repeat: no-repeat;
background-size: 100% 100%;
2025-10-23 16:04:28 +08:00
.minUnicon {
color: var(--primary-color);
}
2025-08-11 11:06:07 +08:00
.content {
padding: 0 32rpx;
}
.avatar {
width: 44rpx;
height: 44rpx;
border-radius: 50%;
position: absolute;
border: 2px solid white;
/* 白色边框 */
background-size: cover;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
transition: all 0.4s ease;
img {
width: 100%;
height: 100%;
border-radius: 50%;
}
}
/* 头像位置 */
.avatar:nth-child(1) {
left: calc(50% - 60rpx);
z-index: 3;
}
.avatar:nth-child(2) {
left: calc(50% - 35rpx);
z-index: 2;
}
.avatar:nth-child(3) {
left: calc(50% - 10rpx);
z-index: 1;
}
/* 悬停效果 */
.avatar:hover {
transform: translateY(-10px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
z-index: 10;
}
/* 搜索框 */
.flex-input {
width: 100%;
display: inline-flex;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
.search-button {
padding: 0 0 0 20rpx;
}
}
/* 轮播图 */
.swipe-view {
width: 100%;
height: 200rpx;
2025-10-23 16:04:28 +08:00
// background-color: antiquewhite;
2025-08-11 11:06:07 +08:00
border-radius: 14rpx;
margin-top: 36rpx;
2025-10-23 16:04:28 +08:00
// background-image: url('/static/image/swiper.jpg');
// background-repeat: no-repeat;
// background-size: 100% 100%;
2025-08-11 11:06:07 +08:00
}
.title {
padding: 24rpx 0;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 500;
font-size: 32rpx;
color: #333333;
}
/* 热门公会 */
.hotspot-view {
.hotspot-box {
width: calc(100% - 48rpx);
padding: 24rpx;
// min-height: calc(268rpx - 48rpx);
background: #FFFFFF;
border-radius: 20rpx;
margin-bottom: 24rpx;
/* */
display: inline-flex;
align-items: center;
flex-wrap: nowrap;
justify-content: space-between;
flex-direction: row;
/* 头像 */
.head-portrait {
2025-10-23 16:04:28 +08:00
width: 120rpx;
height: 120rpx;
2025-08-11 11:06:07 +08:00
border-radius: 50%;
img {
width: 100%;
height: 100%;
border-radius: 50%;
}
}
/* 中间信息 */
.info-box {
padding: 0 24rpx;
// width: 55%;
.icon-box {
width: 20rpx;
height: 20rpx;
margin-left: 5rpx;
}
/* 会长样式 */
.chairman {
2025-10-23 16:04:28 +08:00
min-width: 106rpx;
2025-08-11 11:06:07 +08:00
height: 36rpx;
padding: 0 12rpx;
color: #fff;
font-size: 24rpx;
text-align: right;
2025-10-23 16:04:28 +08:00
background: var(--subss-color);
2025-08-11 11:06:07 +08:00
border-radius: 116rpx 116rpx 116rpx 116rpx;
2025-10-23 16:04:28 +08:00
border: 2rpx solid var(--subss-color);
2025-08-11 11:06:07 +08:00
position: relative;
left: 10rpx;
margin: 32rpx 0;
2025-10-23 16:04:28 +08:00
display: inline-flex;
.truncate-three {
text-align: left;
}
2025-08-11 11:06:07 +08:00
.chairman-portrait {
width: 50rpx;
height: 50rpx;
border-radius: 50%;
border: 2rpx solid #FFFFFF;
position: absolute;
top: -10rpx;
left: -20rpx;
img {
width: 100%;
height: 100%;
border-radius: 50%;
}
}
2025-10-23 16:04:28 +08:00
.chairman-name {
margin-left: 0.9rem;
}
2025-08-11 11:06:07 +08:00
}
.id-title {
font-size: 24rpx;
color: #666666;
margin-left: 24rpx;
}
.subhead-title {
display: block;
font-weight: 400;
font-size: 24rpx;
color: #666666;
margin: 8rpx 0;
}
.like-box {
display: inline-flex;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
padding: 6rpx 24rpx;
background: #2AFEC0;
border-radius: 35rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 28rpx;
color: #333333;
margin: 8rpx 0;
}
}
/* 右边按钮 */
.right-button {
2025-10-23 16:04:28 +08:00
text-align: center;
2025-08-11 11:06:07 +08:00
.apply-button {
display: inline-block;
2025-10-23 16:04:28 +08:00
background: var(--primary-color);
font-size: var(--font-button-size);
color: var(--font-button-color);
2025-08-11 11:06:07 +08:00
border-radius: 68rpx;
text-align: center;
2025-10-23 16:04:28 +08:00
padding: 4rpx 30rpx;
2025-08-11 11:06:07 +08:00
}
.online-view {
// display: inline-block;
margin-top: 24rpx;
padding: 12rpx 8rpx;
text-align: right;
width: 160rpx;
height: 44rpx;
line-height: 44rpx;
2025-10-23 16:04:28 +08:00
// background: #333333;
2025-08-11 11:06:07 +08:00
border-radius: 92rpx 92rpx 92rpx 92rpx;
position: relative;
.avatars-container {
position: absolute;
top: 10rpx;
left: 40%;
}
.online-people {
2025-10-23 16:04:28 +08:00
color: rgba(0, 0, 0, 0.5);
2025-08-11 11:06:07 +08:00
font-size: 24rpx;
2025-10-23 16:04:28 +08:00
text-align: left;
display: inline-block;
/* width: 6ch; */
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
word-break: keep-all;
2025-08-11 11:06:07 +08:00
}
}
}
}
}
}
</style>