| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- <template>
- <div class="app-container">
- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
- <el-form-item label="直播间ID" prop="liveId">
- <el-input
- v-model="queryParams.liveId"
- placeholder="请输入直播间ID"
- clearable
- :disabled="liveAbled"
- size="small"
- @keyup.enter.native="handleQuery"
- />
- </el-form-item>
- <el-form-item label="任务名称" prop="taskName">
- <el-input
- v-model="queryParams.taskName"
- placeholder="请输入任务名称"
- clearable
- size="small"
- @keyup.enter.native="handleQuery"
- />
- </el-form-item>
- <el-form-item label="任务类型" prop="taskType">
- <el-select v-model="queryParams.taskType" placeholder="请选择任务类型" clearable size="small">
- <el-option v-for="i in taskTypeOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
- </el-select>
- </el-form-item>
- <!-- <el-form-item label="触发类型" prop="triggerType">-->
- <!-- <el-select v-model="queryParams.triggerType" placeholder="请选择触发类型" clearable size="small">-->
- <!-- <el-option v-for="i in triggerTypeOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>-->
- <!-- </el-select>-->
- <!-- </el-form-item>-->
- <el-form-item label="状态" prop="status">
- <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
- <el-option v-for="i in statusOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
- </el-form-item>
- </el-form>
- <el-row :gutter="10" class="mb8">
- <el-col :span="1.5">
- <el-button
- type="primary"
- plain
- icon="el-icon-plus"
- size="mini"
- @click="handleAdd"
- v-hasPermi="['live:task:add']"
- >新增</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button
- type="success"
- plain
- icon="el-icon-edit"
- size="mini"
- :disabled="single"
- @click="handleUpdate"
- v-hasPermi="['live:task:edit']"
- >修改</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button
- type="danger"
- plain
- icon="el-icon-delete"
- size="mini"
- :disabled="multiple"
- @click="handleDelete"
- v-hasPermi="['live:task:remove']"
- >删除</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button
- type="warning"
- plain
- icon="el-icon-download"
- size="mini"
- :loading="exportLoading"
- @click="handleExport"
- v-hasPermi="['live:task:export']"
- >导出</el-button>
- </el-col>
- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
- </el-row>
- <el-table border v-loading="loading" :data="taskList" @selection-change="handleSelectionChange">
- <el-table-column type="selection" width="55" align="center" />
- <el-table-column label="编号" align="center" prop="id" />
- <el-table-column label="任务名称" align="center" prop="taskName" />
- <el-table-column label="任务类型" align="center" prop="taskType" :formatter="taskTypeFormatter" />
- <el-table-column label="触发类型" align="center" prop="triggerType" :formatter="triggerTypeFormatter" />
- <el-table-column label="触发时间" align="center" prop="triggerValue" :formatter="triggerValueFormatter" />
- <el-table-column label="产品名称" align="center" prop="productName" :formatter="productNameFormatter" />
- <el-table-column label="状态" align="center" prop="status" :formatter="statusFormatter" />
- <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
- <template slot-scope="scope">
- <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
- <template slot-scope="scope">
- <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
- <template slot-scope="scope">
- <el-button
- size="mini"
- type="text"
- icon="el-icon-edit"
- @click="handleUpdate(scope.row)"
- v-hasPermi="['live:task:edit']"
- >修改</el-button>
- <el-button
- size="mini"
- type="text"
- icon="el-icon-delete"
- @click="handleDelete(scope.row)"
- v-hasPermi="['live:task:remove']"
- >删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-show="total>0"
- :total="total"
- :page.sync="queryParams.pageNum"
- :limit.sync="queryParams.pageSize"
- @pagination="getList"
- />
- <!-- 添加或修改直播间自动化任务配置对话框 -->
- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
- <el-form ref="form" :model="form" :rules="rules" label-width="80px">
- <el-form-item label="直播间ID" prop="liveId">
- <el-input :disabled="liveAbled" v-model="form.liveId" placeholder="请输入直播间ID" />
- </el-form-item>
- <el-form-item label="任务名称" prop="taskName">
- <el-input v-model="form.taskName" placeholder="请输入任务名称" />
- </el-form-item>
- <el-form-item label="任务类型" prop="taskType">
- <el-select v-model="form.taskType" placeholder="请选择任务类型" @change="updateTaskType()">
- <el-option v-for="i in taskTypeOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="商品选择" prop="content" v-if="form.taskType == 1">
- <el-select v-model="form.content" placeholder="请选择商品" ref="selectRef" >
- <el-option v-for="i in productOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
- <!-- 加载载中状态 -->
- <div v-if="isLoading" class="loading-indicator">
- <i class="el-icon-loading"></i>
- <span>加载中...</span>
- </div>
- <!-- 没有更多数据 -->
- <div v-if="!hasMore && !isLoading" class="no-more">
- 没有更多数据了
- </div>
- </el-select>
- </el-form-item>
- <el-form-item label="红包选择" prop="content" v-if="form.taskType == 2">
- <el-select v-model="form.content" placeholder="请选择红包" ref="selectRef" >
- <el-option v-for="i in redOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
- <!-- 加载载中状态 -->
- <div v-if="isLoading" class="loading-indicator">
- <i class="el-icon-loading"></i>
- <span>加载中...</span>
- </div>
- <!-- 没有更多数据 -->
- <div v-if="!hasMore && !isLoading" class="no-more">
- 没有更多数据了
- </div>
- </el-select>
- </el-form-item>
- <el-form-item label="抽奖选择" prop="content" v-if="form.taskType == 4">
- <el-select v-model="form.content" placeholder="请选择抽奖" ref="selectRef" >
- <el-option v-for="i in lotteryOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
- <!-- 加载载中状态 -->
- <div v-if="isLoading" class="loading-indicator">
- <i class="el-icon-loading"></i>
- <span>加载中...</span>
- </div>
- <!-- 没有更多数据 -->
- <div v-if="!hasMore && !isLoading" class="no-more">
- 没有更多数据了
- </div>
- </el-select>
- </el-form-item>
- <el-form-item label="触发时间" prop="content">
- <el-time-picker
- default-value="2025-01-01 00:00:00"
- v-model="form.triggerValue"
- :picker-options="{
- selectableRange: '00:00:00 - 23:59:59'
- }"
- placeholder="任意时间点">
- </el-time-picker>
- </el-form-item>
- <!-- <el-form-item label="触发类型" prop="triggerType">-->
- <!-- <el-select v-model="form.triggerType" placeholder="请选择触发类型">-->
- <!-- <el-option label="请选择字典生成" value="" />-->
- <!-- </el-select>-->
- <!-- </el-form-item>-->
- <!-- <el-form-item label="触发值" prop="triggerValue">-->
- <!-- <el-input v-model="form.triggerValue" placeholder="请输入触发值" />-->
- <!-- </el-form-item>-->
- <!-- <el-form-item label="任务内容">-->
- <!-- <editor v-model="form.content" :min-height="192"/>-->
- <!-- </el-form-item>-->
- <el-form-item label="状态">
- <el-radio-group v-model="form.status">
- <el-radio :label="1">启用</el-radio>
- <el-radio :label="0">禁用</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" @click="submitForm">确 定</el-button>
- <el-button @click="cancel">取 消</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { listTask, getTask, delTask, addTask, updateTask, exportTask } from "@/api/live/task";
- import {listLiveGoods} from "@/api/live/liveGoods";
- import {listLiveRedConfOn} from "@/api/live/liveRedConf";
- import {listLiveLotteryConfOn} from "@/api/live/liveLotteryConf";
- export default {
- name: "Task",
- data() {
- return {
- taskTypeOptions:[
- {
- value: 1,
- label: "定时卡片推荐商品"
- },
- {
- value: 2,
- label: "定时红包发送"
- },
- {
- value: 4,
- label: "定时抽奖"
- },
- ],
- statusOptions:[{
- value: "0",
- label: "禁用"
- },
- {
- value: "1",
- label: "启用"
- }
- ],
- haveData:{
- goods:false,
- red:false,
- lottery:false
- },
- redOptions:[],
- lotteryOptions:[],
- productOptions:[],
- // 遮罩层
- loading: true,
- // 导出遮罩层
- exportLoading: false,
- // 选中数组
- ids: [],
- // 非单个禁用
- single: true,
- // 非多个禁用
- multiple: true,
- // 显示搜索条件
- showSearch: true,
- // 总条数
- total: 0,
- liveAbled: false,
- // 直播间自动化任务配置表格数据
- taskList: [],
- // 弹出层标题
- title: "",
- // 是否显示弹出层
- open: false,
- // 查询参数
- queryParams: {
- pageNum: 1,
- pageSize: 10,
- liveId: null,
- taskName: null,
- taskType: null,
- triggerType: null,
- triggerValue: null,
- content: null,
- status: null,
- createdTime: null,
- updatedTime: null
- },
- // 表单参数
- form: {},
- // 表单校验
- rules: {
- liveId: [
- { required: true, message: "直播间ID不能为空", trigger: "blur" }
- ],
- taskName: [
- { required: true, message: "任务名称不能为空", trigger: "blur" }
- ],
- taskType: [
- { required: true, message: "任务类型:1-定时推送卡片商品 2-定时发送红包 ", trigger: "change" }
- ],
- triggerType: [
- { required: true, message: "触发类型:相对直播开始时间不能为空", trigger: "change" }
- ],
- triggerValue: [
- { required: true, message: "触发值:绝对时间用yyyy-MM-dd HH:mm:ss,相对时间用分钟数不能为空", trigger: "blur" }
- ],
- status: [
- { required: true, message: "状态:0-禁用 1-启用不能为空", trigger: "blur" }
- ],
- createdTime: [
- { required: true, message: "创建时间不能为空", trigger: "blur" }
- ],
- updatedTime: [
- { required: true, message: "更新时间不能为空", trigger: "blur" }
- ]
- },
- liveId: null,
- listParams: {
- pageNum: 1,
- pageSize: 10,
- liveId: null
- },
- isLoading: false, // 是否正在加载
- hasMore: true, // 是否还有更多数据
- socket:null ,
- };
- },
- watch: {
- // 监听路由的 query 参数变化
- '$route.query': {
- handler(newQuery) {
- if (this.$route.params.liveId) {
- this.liveId = this.$route.params.liveId;
- }else {
- this.liveId = this.$route.query.liveId;
- }
- if(this.liveId == null) {
- return;
- }
- this.liveAbled = true
- if(this.liveId == null) {
- return;
- }
- this.queryParams.liveId = this.liveId;
- this.getList();
- },
- // 初始化时立即执行一次
- immediate: true
- }
- },
- created() {
- this.socket = this.$store.state.liveWs[this.liveId]
- },
- methods: {
- statusFormatter(row, column, value){
- if (!value) return '--'; // 空值处理
- switch ( value){
- case 0:
- return "禁用";
- case 1:
- return "启用";
- default:
- return "--";
- }
- },
- taskTypeFormatter(row, column, value){
- if (!value) return '--'; // 空值处理
- switch (value) {
- case 1:
- return "定时推送卡片商品";
- case 2:
- return "定时发送红包";
- case 4:
- return "定时抽奖";
- default:
- return "--";
- }
- },
- triggerTypeFormatter(row, column, value){
- if (!value) return '--'; // 空值处理
- switch (value) {
- case 1:
- return "相对直播开始时间";
- case 2:
- return "相对时间";
- default:
- return "--";
- }
- },
- productNameFormatter(row, column, value){
- let content = JSON.parse(row.content)
- if(content.productName) {
- return content.productName
- }
- return "--";
- },
- triggerValueFormatter(row, column, value) {
- if (!value) return '--'; // 空值处理
- // 创建日期对象(兼容时间戳和字符串)
- let date;
- if (typeof value === 'number') {
- // 处理时间戳(注意:如果是10位时间戳需要乘以1000)
- date = new Date(value.toString().length === 10 ? value * 1000 : value);
- } else if (typeof value === 'string') {
- // 处理字符串格式(尝试直接转换)
- date = new Date(value);
- } else {
- return '格式错误';
- }
- // 检查日期是否有效
- if (isNaN(date.getTime())) {
- return '无效时间';
- }
- // 格式化日期为 "yyyy-MM-dd HH:mm:ss"
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- const seconds = String(date.getSeconds()).padStart(2, '0');
- return `${hours}:${minutes}:${seconds}`;
- },
- async updateTaskType(){
- this.hasMore = true;
- this.listParams = {
- pageNum: 1,
- pageSize: 10,
- liveId: null
- }
- if (this.isLoading || !this.hasMore) return;
- this.isLoading = true;
- this.listParams.liveId = this.liveId;
- if(this.listParams.liveId == null) {
- this.$message.error("页面错误,请联系管理员");
- return;
- }
- try{
- if (this.form.taskType == 1) {
- await this.addGoodsList();
- }else if (this.form.taskType == 2) {
- await this.addRedList();
- }else if (this.form.taskType == 4) {
- await this.addLotteryList();
- }
- }catch ( err){
- console.error('加载数据失败:', err);
- }finally {
- this.isLoading = false;
- }
- },
- addGoodsList() {
- if(this.haveData.goods) return
- listLiveGoods(this.listParams).then(res => {
- if(res.rows.length > 0) {
- res.rows.forEach(item => {
- // 根据productName和goodsId组装成为label和value
- this.productOptions.push({
- value: item.goodsId,
- label: item.productName
- })
- })
- this.listParams.pageNum++;
- // 判断是否还有更多数据
- this.hasMore = this.productOptions.length < res.total;
- if (this.hasMore) {
- this.addGoodsList();
- } else {
- this.haveData.goods = true;
- }
- } else {
- this.hasMore = false;
- this.haveData.goods = true;
- }
- });
- },
- addRedList() {
- if(this.haveData.red) return
- listLiveRedConfOn(this.listParams).then(res => {
- if(res.rows.length > 0) {
- res.rows.forEach(item => {
- // 根据productName和goodsId组装成为label和value
- this.redOptions.push({
- value: item.redId,
- label: item.desc
- })
- })
- this.listParams.pageNum++;
- // 判断是否还有更多数据
- this.hasMore = this.redOptions.length < res.total;
- if (this.hasMore) {
- this.addRedList();
- } else {
- this.haveData.red = true
- }
- } else {
- this.haveData.red = true
- this.hasMore = false;
- }
- });
- },
- addLotteryList() {
- if(this.haveData.lottery) return
- listLiveLotteryConfOn(this.listParams).then(res => {
- if(res.rows.length > 0) {
- res.rows.forEach(item => {
- // 根据productName和goodsId组装成为label和value
- this.lotteryOptions.push({
- value: item.lotteryId,
- label: item.desc
- })
- })
- this.listParams.pageNum++;
- // 判断是否还有更多数据
- this.hasMore = this.lotteryOptions.length < res.total;
- if (this.hasMore) {
- this.addRedList();
- } else {
- this.haveData.lottery = true
- }
- } else {
- this.haveData.lottery = true
- this.hasMore = false;
- }
- });
- },
- /** 查询直播间自动化任务配置列表 */
- getList() {
- if(this.liveId == null) {
- this.$message.error("页面错误,请联系管理员");
- return;
- }
- this.loading = true;
- listTask(this.queryParams).then(res => {
- this.taskList = res.rows;
- this.total = res.total;
- this.loading = false;
- });
- },
- // 取消按钮
- cancel() {
- this.open = false;
- this.reset();
- },
- // 表单重置
- reset() {
- this.form = {
- id: null,
- liveId: this.liveId,
- taskName: null,
- taskType: null,
- triggerType: null,
- triggerValue: null,
- content: null,
- status: 1,
- createdTime: null,
- updatedTime: null
- };
- this.listParams={
- pageNum: 1,
- pageSize: 10,
- liveId: this.liveId
- }
- this.hasMore = true;
- this.resetForm("form");
- },
- /** 搜索按钮操作 */
- handleQuery() {
- this.queryParams.pageNum = 1;
- this.getList();
- },
- /** 重置按钮操作 */
- resetQuery() {
- this.resetForm("queryForm");
- this.handleQuery();
- },
- // 多选框选中数据
- handleSelectionChange(selection) {
- this.ids = selection.map(item => item.id)
- this.single = selection.length!==1
- this.multiple = !selection.length
- },
- /** 新增按钮操作 */
- handleAdd() {
- this.reset();
- this.open = true;
- this.title = "添加直播间自动化任务配置";
- },
- /** 修改按钮操作 */
- async handleUpdate(row) {
- this.reset();
- if(row.taskType == 1){
- await this.addGoodsList();
- }else if(row.taskType == 2){
- await this.addRedList();
- }else if(row.taskType == 4){
- await this.addLotteryList();
- }
- const id = row.id || this.ids
- getTask(id).then(response => {
- this.form = response.data;
- let content = JSON.parse( response.data.content)
- if (this.form.taskType == 1) {
- this.form.content = content.goodsId;
- }else if (this.form.taskType == 2) {
- this.form.content = content.desc;
- }else if (this.form.taskType == 4) {
- this.form.content = content.desc;
- }
- this.open = true;
- this.title = "修改直播间自动化任务配置";
- });
- },
- /** 提交按钮 */
- submitForm() {
- this.form.liveId = this.liveId;
- if(this.liveId == null) {
- this.msgError("请选择直播间");
- return;
- }
- this.$refs["form"].validate(valid => {
- if (valid) {
- if (this.form.id != null) {
- updateTask(this.form).then(response => {
- this.msgSuccess("修改成功");
- this.open = false;
- this.getList();
- });
- } else {
- addTask(this.form).then(response => {
- this.msgSuccess("新增成功");
- this.open = false;
- this.getList();
- });
- }
- }
- });
- },
- /** 删除按钮操作 */
- handleDelete(row) {
- if(this.socket == null) {
- this.$message.error("请进入直播间后,在进行操作!")
- return;
- }
- const ids = row.id || this.ids;
- this.$confirm('是否确认删除直播间自动化任务配置编号为"' + ids + '"的数据项?', "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- return delTask(ids);
- }).then(() => {
- this.getList();
- this.msgSuccess("删除成功");
- const msg={
- cmd:'delAutoTask',
- data:row.absValue,
- liveId:this.liveId,
- userType:1
- }
- this.socket.send(JSON.stringify( msg))
- }).catch(() => {});
- },
- /** 导出按钮操作 */
- handleExport() {
- const queryParams = this.queryParams;
- this.$confirm('是否确认导出所有直播间自动化任务配置数据项?', "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(() => {
- this.exportLoading = true;
- return exportTask(queryParams);
- }).then(response => {
- this.download(response.msg);
- this.exportLoading = false;
- }).catch(() => {});
- },
- }
- };
- </script>
- <style scoped>
- .loading-indicator {
- padding: 10px;
- text-align: center;
- color: #606266;
- font-size: 12px;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .loading-indicator .el-icon-loading {
- margin-right: 5px;
- animation: rotate 1s linear infinite;
- }
- .no-more {
- padding: 10px;
- text-align: center;
- color: #909399;
- font-size: 12px;
- }
- @keyframes rotate {
- from { transform: rotate(0deg); }
- to { transform: rotate(360deg); }
- }
- </style>
|