Files
tk-mini-program-PC/src/components/mineSubComponent/AnchorLibrary.vue

560 lines
14 KiB
Vue
Raw Normal View History

2025-07-31 22:07:21 +08:00
<template>
<!-- 主播库 -->
<div class="anchor-library">
<el-splitter>
2025-08-05 22:07:07 +08:00
<el-splitter-panel size="75%">
2025-07-31 22:07:21 +08:00
<!-- 主播列表 -->
<div class="demo-panel">
<div
class="anchor-library-list"
style="overflow: auto"
v-infinite-scroll="load"
2025-08-21 21:36:08 +08:00
v-if="list.length !== 0"
2025-07-31 22:07:21 +08:00
>
<div class="anchor-library-card" v-for="(item, index) in list" :key="index">
<div class="card-content">
2025-08-12 22:05:06 +08:00
<div class="card-avatar">
<img
style="width: 100%; height: 100%; border-radius: 100px"
:src="item.headerIcon"
alt=""
/>
</div>
2025-07-31 22:07:21 +08:00
<div class="personalInformation">
2025-08-12 22:05:06 +08:00
<div class="name">{{ item.anchorId }}</div>
2025-07-31 22:07:21 +08:00
<div class="GenderAndCountry">
2025-08-12 22:05:06 +08:00
<div
class="Gender"
:style="{
background: item.gender == 1 ? '#59D8DB' : '#F3876F',
}"
>
2025-08-27 22:06:45 +08:00
{{ item.gender == 1 ?t('man') : t('woman') }}
<!-- gj男女 -->
2025-08-12 22:05:06 +08:00
</div>
<div class="Country">{{ item.country }}</div>
2025-07-31 22:07:21 +08:00
</div>
</div>
<div class="card-Operation">
2025-08-12 22:05:06 +08:00
<!-- 编辑 -->
<div class="modify" @click="anchormodify(item)">
<img class="modify-icon" src="@/assets/Editor.png" alt="" />
2025-07-31 22:07:21 +08:00
</div>
2025-08-12 22:05:06 +08:00
<!-- 删除 -->
<div class="delete" @click="anchordelete(item.id)">
<img class="delete-icon" src="@/assets/Delete.png" alt="" />
2025-07-31 22:07:21 +08:00
</div>
</div>
</div>
</div>
</div>
2025-08-21 21:36:08 +08:00
<div class="chatNotDeta" v-if="list.length === 0">
2025-08-27 22:06:45 +08:00
<div class="chatNotDeta-text">{{ t('YouDonHaveALiveStreamerYetHurryUpAndAddOne') }}</div>
<!-- gj您还没有主播快去添加吧 -->
2025-08-21 21:36:08 +08:00
</div>
2025-07-31 22:07:21 +08:00
</div>
</el-splitter-panel>
<el-splitter-panel size="25%" :collapsible="true" :resizable="false">
<!-- 添加或修改主播 -->
<div class="demo-panel">
<div class="add-anchor-library">
2025-08-12 22:05:06 +08:00
<div class="title">
<img class="titleimg" src="@/assets/embellish.png" alt="" />
2025-08-27 22:06:45 +08:00
<div v-if="!anchormodifystate">{{ t('AddMyStreamer') }}</div>
<!-- gj添加主播 -->
<div v-if="anchormodifystate">{{ t('ModifyMyStreamer') }}</div>
<!-- gj修改主播 -->
2025-08-12 22:05:06 +08:00
<img class="titleimg" src="@/assets/embellish.png" alt="" />
</div>
2025-07-31 22:07:21 +08:00
<div class="add-anchor-library-content">
<div class="input-name">
<!-- 主播名称 -->
2025-08-12 22:05:06 +08:00
<el-input
@blur="blur()"
v-model="anchorName"
size="large"
2025-08-27 22:06:45 +08:00
:placeholder="t('PleaseEnterTheNameOfTheHost')"
2025-08-12 22:05:06 +08:00
/>
2025-07-31 22:07:21 +08:00
</div>
<div class="country">
<!-- 国家 -->
<el-select-v2
v-model="countryvalue"
filterable
:options="country"
2025-08-27 22:06:45 +08:00
:placeholder="t('PleaseSelectACountry')"
2025-07-31 22:07:21 +08:00
size="large"
style="vertical-align: middle"
class="select"
/>
</div>
2025-08-27 22:06:45 +08:00
<!-- gj选择国家 -->
2025-07-31 22:07:21 +08:00
<div class="gender">
<!-- 性别 -->
<el-select-v2
v-model="gendervalue"
filterable
:options="genderOptions"
size="large"
2025-08-27 22:06:45 +08:00
:placeholder="t('PleaseSelectACountry')"
2025-07-31 22:07:21 +08:00
style="vertical-align: middle"
class="select"
/>
2025-08-27 22:06:45 +08:00
<!-- gj男女 -->
2025-07-31 22:07:21 +08:00
</div>
2025-08-27 22:06:45 +08:00
<div class="Confirm" @click="Confirm()">{{ t('Confirm') }}</div>
<div class="Reset" @click="Reset()">{{ t('Reset') }}</div>
<div class="Reset" v-if="anchormodifystate" @click="cancel()">{{ t('Cancel') }}</div>
2025-07-31 22:07:21 +08:00
</div>
</div>
</div>
</el-splitter-panel>
</el-splitter>
</div>
2025-08-12 22:05:06 +08:00
<!-- 确认删除弹窗 -->
2025-08-21 21:36:08 +08:00
<el-dialog
center
2025-08-12 22:05:06 +08:00
class="center-dialog"
v-model="centerDialogVisible"
2025-08-27 22:06:45 +08:00
:title="t('Hint')"
2025-08-12 22:05:06 +08:00
width="200"
align-center
>
2025-08-27 22:06:45 +08:00
<!-- gj提示 -->
<span>{{ t('ConfirmTheDeletionOfThisStreamer') }}</span>
<!-- gj确认删除此主播 -->
2025-08-12 22:05:06 +08:00
<template #footer>
<div class="dialog-footer">
2025-08-27 22:06:45 +08:00
<el-button @click="centerDialogVisible = false">{{ t('Cancel') }}</el-button>
<!-- gj取消 -->
<el-button type="primary" @click="deleteAnchor()"> {{ t('Confirm') }}</el-button>
<!-- gj确认 -->
2025-08-12 22:05:06 +08:00
</div>
</template>
</el-dialog>
2025-07-31 22:07:21 +08:00
</template>
<script setup>
import {
ref, // 响应式基础
watch, // 侦听器
onMounted, // 组件挂载完成后执行
onUpdated, // 组件更新后执行
onUnmounted, // 组件销毁前执行
} from "vue";
2025-08-12 22:05:06 +08:00
import {
getAnchorList,
getAnchorAvatar,
addAnchor,
delAnchor,
editAnchor,
} from "@/api/account";
2025-07-31 22:07:21 +08:00
import { getCountryNamesArray } from "../../utils/countryUtil";
2025-08-12 22:05:06 +08:00
import { ElLoading } from "element-plus";
import { ElMessage } from "element-plus";
import { setStorage, getStorage, getPromiseStorage } from "@/utils/storage.js";
2025-08-27 22:06:45 +08:00
//
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
window['$t'] = t
//
2025-07-31 22:07:21 +08:00
const country = ref([]);
country.value = getCountryNamesArray(); //国家条目
const genderOptions = [
2025-08-27 22:06:45 +08:00
{ value: 1, label: t('man') },
{ value: 2, label: t('woman') },
2025-07-31 22:07:21 +08:00
]; // 性别选项
2025-08-05 22:07:07 +08:00
const gendervalue = ref(null); // 性别值
2025-08-12 22:05:06 +08:00
const countryvalue = ref(null); //国家
const anchorName = ref(null); // 主播名称
2025-08-21 21:36:08 +08:00
const list = ref([]);
2025-08-12 22:05:06 +08:00
const user = ref(null); // 用户信息
const AnchorProfilePicture = ref(null); // 主播头像
const centerDialogVisible = ref(false); // 确认删除弹窗
const anchormodifystate = ref(false); // 编辑
const anchormodifystateId = ref(null); // 主播头像
// 获取主播列表
function AnchorList() {
getAnchorList({ id: user.value.id })
.then((res) => {
list.value = res;
})
.catch((err) => {
console.log(err);
});
}
//编辑主播
function anchormodify(item) {
if (anchormodifystate.value == true) {
cancel();
return;
}
anchormodifystateId.value = item.id;
anchorName.value = item.anchorId;
gendervalue.value = item.gender;
countryvalue.value = item.country;
AnchorProfilePicture.value = item.headerIcon.split("/").pop();
anchormodifystate.value = true;
}
// 取消编辑
function cancel() {
anchormodifystateId.value = null;
anchorName.value = null;
gendervalue.value = null;
countryvalue.value = null;
AnchorProfilePicture.value = null;
anchormodifystate.value = false;
}
// 删除主播
const deleteAnchorID = ref(null);
const deleteAnchor = () => {
2025-08-21 21:36:08 +08:00
delAnchor({ id: deleteAnchorID.value })
.then((res) => {
centerDialogVisible.value = false;
2025-08-27 22:06:45 +08:00
ElMessage.success(t('DeletedSuccessfully'));
// gj删除成功
2025-08-21 21:36:08 +08:00
AnchorList();
2025-08-29 13:31:08 +08:00
cancel();
2025-08-21 21:36:08 +08:00
})
.catch((err) => {});
2025-08-12 22:05:06 +08:00
};
function anchordelete(id) {
deleteAnchorID.value = id;
centerDialogVisible.value = true;
}
// 加载更多
function load() {}
// 确认添加或修改主播
function Confirm() {
if (anchorName.value == null || anchorName.value == "") {
2025-08-27 22:06:45 +08:00
ElMessage.error(t('PleaseEnterTheNameOfTheHost'));
// gj请输入主播名称
2025-08-12 22:05:06 +08:00
return;
}
if (gendervalue.value == null) {
2025-08-27 22:06:45 +08:00
ElMessage.error(t('PleaseSelectGender'));
// gj请选择性别
2025-08-12 22:05:06 +08:00
return;
}
if (countryvalue.value == null) {
2025-08-27 22:06:45 +08:00
ElMessage.error(t('PleaseSelectACountry'));
//gj请选择国家
2025-08-12 22:05:06 +08:00
return;
}
//修改主播还是添加
if (anchormodifystate.value) {
//修改主播
editAnchor({
id: anchormodifystateId.value,
anchorId: anchorName.value,
headerIcon: AnchorProfilePicture.value,
gender: gendervalue.value,
country: countryvalue.value,
createUserId: user.value.id,
})
.then((res) => {
2025-08-27 22:06:45 +08:00
ElMessage.success(t('ModificationSuccessful'));
// gj修改成功
2025-08-12 22:05:06 +08:00
cancel();
AnchorList();
})
.catch((err) => {
console.log(err);
});
} else {
//添加主播
addAnchor({
anchorId: anchorName.value,
headerIcon: AnchorProfilePicture.value,
gender: gendervalue.value,
country: countryvalue.value,
createUserId: user.value.id,
})
.then((res) => {
2025-08-27 22:06:45 +08:00
ElMessage.success(t('AddedSuccessfully'));
2025-08-12 22:05:06 +08:00
AnchorList();
})
.catch((err) => {
console.log(err);
});
}
}
// 重置
function Reset() {
anchorName.value = null;
gendervalue.value = null;
countryvalue.value = null;
2025-08-05 22:07:07 +08:00
}
2025-08-12 22:05:06 +08:00
//输入框失去焦点
function blur() {
if (anchorName.value == null || anchorName.value == "") {
2025-08-27 22:06:45 +08:00
ElMessage.error(t('PleaseEnterTheNameOfTheHost'));
// gj请输入主播名称
2025-08-12 22:05:06 +08:00
return;
}
const loading = ElLoading.service({
lock: true,
2025-08-27 22:06:45 +08:00
text: t('CheckTheStreamerAt'),
// gj正在检查主播
2025-08-12 22:05:06 +08:00
background: "rgba(0, 0, 0, 0.7)",
});
getAnchorAvatar({ name: anchorName.value })
.then((res) => {
loading.close();
AnchorProfilePicture.value = res;
})
.catch((err) => {
loading.close();
console.log(err);
});
}
// 组件挂载完成后执行
onMounted(() => {
getPromiseStorage("user")
.then((res) => {
user.value = res;
AnchorList();
})
.catch((err) => {
console.log(err);
});
});
const refname = ref("");
2025-07-31 22:07:21 +08:00
watch(refname, async (newQuestion, oldQuestion) => {
// 变化后执行
});
onUpdated(() => {
// 组件更新后执行
});
onUnmounted(() => {
// 组件销毁前执行
});
</script>
<style scoped lang="less">
.anchor-library {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
2025-08-20 22:11:41 +08:00
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
2025-07-31 22:07:21 +08:00
}
.anchor-library-list {
width: 100%;
height: 100%;
}
2025-08-21 21:36:08 +08:00
.chatNotDeta{
width: 100%;
height: 100%;
background-color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
}
.chatNotDeta-text{
font-size: 20px;
color: #03aba8;
font-weight: bold;
}
2025-07-31 22:07:21 +08:00
.anchor-library-card {
width: 100%;
height: 150px;
margin-bottom: 15px;
margin-top: 15px;
display: flex;
justify-content: center;
align-items: center;
}
.card-content {
width: 90%;
height: 100%;
2025-08-15 13:05:19 +08:00
border-radius: 10px;
2025-08-12 22:05:06 +08:00
background-image: url(../../assets/PKbackground.png);
background-size: 100% 100%;
2025-07-31 22:07:21 +08:00
transition: all 0.4s ease;
display: flex;
align-items: center;
}
.card-content:hover {
2025-08-15 13:05:19 +08:00
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
2025-08-12 22:05:06 +08:00
transform: scale(1.05);
2025-07-31 22:07:21 +08:00
opacity: 0.8;
}
.card-avatar {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #ffffff;
margin-left: 20px;
}
.personalInformation {
width: calc(100% - 340px);
height: 100px;
margin-left: 20px;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.name {
font-size: 20px;
font-weight: bold;
color: #333333;
}
.GenderAndCountry {
display: flex;
align-items: center;
}
.Gender {
font-size: 16px;
2025-08-12 22:05:06 +08:00
color: #ffffff;
2025-07-31 22:07:21 +08:00
border-radius: 50px;
padding: 2px 20px 2px 20px;
margin-right: 20px;
}
.Country {
font-size: 16px;
color: #666666;
border-radius: 50px;
background-color: #ffffff;
padding: 2px 20px 2px 20px;
}
.card-Operation {
width: 200px;
height: 100px;
margin-left: 20px;
margin-right: 20px;
display: flex;
align-items: center;
justify-content: space-around;
}
.modify-icon {
width: 30px;
height: 30px;
2025-08-12 22:05:06 +08:00
transition: all 0.4s ease;
}
.modify-icon:hover {
transform: scale(1.2);
2025-07-31 22:07:21 +08:00
}
2025-08-15 13:05:19 +08:00
.modify-icon:active {
transition: all 0.1s ease;
transform: scale(0.95) !important;
}
2025-07-31 22:07:21 +08:00
.delete-icon {
width: 30px;
height: 30px;
2025-08-12 22:05:06 +08:00
transition: all 0.4s ease;
}
2025-08-15 13:05:19 +08:00
.delete-icon:active {
transition: all 0.1s ease;
transform: scale(0.95) !important;
}
2025-08-12 22:05:06 +08:00
.delete-icon:hover {
transform: scale(1.2);
2025-07-31 22:07:21 +08:00
}
.demo-panel {
width: 100%;
height: 100%;
}
.add-anchor-library {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.title {
2025-08-12 22:05:06 +08:00
width: 80%;
2025-07-31 22:07:21 +08:00
height: 70px;
font-size: 24px;
font-weight: bold;
color: #333333;
text-align: center;
line-height: 70px;
2025-08-12 22:05:06 +08:00
display: flex;
align-items: center;
justify-content: space-evenly;
}
.titleimg {
width: 44px;
height: 30px;
2025-07-31 22:07:21 +08:00
}
.add-anchor-library-content {
width: 100%;
height: calc(100% - 70px);
display: flex;
flex-direction: column;
align-items: center;
}
.input-name {
width: 80%;
height: 50px;
margin-top: 20px;
}
.country {
width: 80%;
height: 50px;
margin-top: 20px;
}
.gender {
width: 80%;
height: 80px;
margin-top: 20px;
}
.select {
width: 100%;
}
.Confirm {
2025-08-12 22:05:06 +08:00
width: 400px;
2025-07-31 22:07:21 +08:00
height: 50px;
margin-top: 200px;
text-align: center;
line-height: 50px;
2025-08-12 22:05:06 +08:00
background-image: linear-gradient(to top, #4fcacd, #5fdbde);
color: #ffffff;
font-size: 22px;
2025-07-31 22:07:21 +08:00
transition: all 0.4s ease;
2025-08-12 22:05:06 +08:00
border-radius: 25px;
2025-07-31 22:07:21 +08:00
}
.Confirm:hover {
2025-08-12 22:05:06 +08:00
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
2025-07-31 22:07:21 +08:00
transform: scale(1.1);
opacity: 0.8;
}
2025-08-15 13:05:19 +08:00
.Confirm:active {
transition: all 0.1s ease;
transform: scale(0.95) !important;
}
2025-07-31 22:07:21 +08:00
.Reset {
2025-08-12 22:05:06 +08:00
width: 400px;
2025-07-31 22:07:21 +08:00
height: 50px;
margin-top: 30px;
text-align: center;
line-height: 50px;
2025-08-12 22:05:06 +08:00
background-image: linear-gradient(to top, #e4ffff, #ffffff);
border: 1px solid #4fcacd;
color: #03aba8;
font-size: 22px;
2025-07-31 22:07:21 +08:00
transition: all 0.4s ease;
2025-08-12 22:05:06 +08:00
border-radius: 25px;
2025-07-31 22:07:21 +08:00
}
.Reset:hover {
2025-08-12 22:05:06 +08:00
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
2025-07-31 22:07:21 +08:00
transform: scale(1.1);
opacity: 0.8;
}
2025-08-15 13:05:19 +08:00
.Reset:active {
transition: all 0.1s ease;
transform: scale(0.95) !important;
}
2025-08-12 22:05:06 +08:00
.center-dialog {
background-color: #03aba8;
}
2025-07-31 22:07:21 +08:00
</style>