import { listBroadcast, getAddBroadcast, updateBroadcast, DeleteBroadcast, getBroadcast,dataInfo } from '../../api/broadcast' export default { data() { return { tableData: [ // { // id: 1, // createTime: "2025-06-24 10:00:00", // content: "内isjisjfidjfjfjffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff容", // createUser: "创建人", // updateTime: "2025-06-24 10:00:00", // updateUser: "修改人", // }, // { // id: 2, // createTime: "2025-06-24 10:00:00", // content: "内容", // createUser: "创建人", // updateTime: "2025-06-24 10:00:00", // updateUser: "修改人", // }, ], listParams: { pageNum: 1, pageSize: 50 }, addParams: { content: "", }, editParams: { content: "", id: "", }, dialogVisible: false, bthLoading: false, broadcastLoading: false, editDialogVisible: false, editLoading: false, byteCount: "", isOverLimit: false, } }, mounted() { let token try{ token =JSON.parse(localStorage.getItem('token')) }catch(e){ console.log(e); } if (token) { this.fetchList(this.listParams); } }, methods: { async fetchList(params) { this.setLoading('broadcastLoading', true); const res = await listBroadcast(params) if (res.code === 200) { this.tableData = res.rows } this.setLoading('broadcastLoading', false); }, async addBroadcast(params) { this.setLoading('bthLoading', true); const res = await getAddBroadcast(params) if (res.code === 200) { this.$message.success(this.$t("backendSystem.addSuccess")) this.dialogVisible = false; this.fetchList(this.listParams); } this.setLoading('bthLoading', false); }, async getBroadcast(params) { this.setLoading('editLoading', true); const res = await dataInfo(params) if (res.code === 200) { this.editParams = res.data this.editDialogVisible = true; } this.setLoading('editLoading', false); }, async editBroadcast(params) { this.setLoading('editLoading', true); const res = await updateBroadcast(params) if (res.code === 200) { this.$message.success(this.$t("backendSystem.editSuccess")) this.editDialogVisible = false; this.fetchList(this.listParams); } this.setLoading('editLoading', false); }, async deleteBroadcast(params) { const res = await DeleteBroadcast(params) if (res.code === 200) { this.$message.success(this.$t("backendSystem.deleteSuccess")) this.fetchList(this.listParams); } }, handelAddBroadcast() { this.dialogVisible = true; }, handleClose() { this.dialogVisible = false; this.addParams.content = "" }, sureAddBroadcast() { this.addParams.content = this.addParams.content.trim() this.addParams.content = this.addParams.content.replace(/[\r\n]/g, ''); if (!this.addParams.content) { this.$message.warning(this.$t("backendSystem.pleaseInputContent")) return } this.addBroadcast(this.addParams); }, sureEditBroadcast() { this.editParams.content=this.editParams.content.trim() this.editParams.content = this.editParams.content.replace(/[\r\n]/g, ''); if (!this.editParams.content) { this.$message.warning(this.$t("backendSystem.pleaseInputContent")) return } this.editBroadcast(this.editParams); }, handleEdit(row) { this.getBroadcast({ id: row.id }); }, handleEditClose() { this.editDialogVisible = false; this.editParams.content = "" }, handelDelete(row) { this.deleteBroadcast({ id: row.id }); }, getUtf8Bytes(str) { let bytes = 0; for (let i = 0; i < str.length; i++) { const code = str.charCodeAt(i); if (code <= 0x7f) bytes += 1; else if (code <= 0x7ff) bytes += 2; else if (code <= 0xffff) bytes += 3; else bytes += 4; } return bytes; }, handleInput(val, type = 'add') { let bytes = this.getUtf8Bytes(val); if (bytes > 100) { this.isOverLimit = true; // 截断到100字节 let newVal = ''; let total = 0; for (let ch of val) { let chBytes = this.getUtf8Bytes(ch); if (total + chBytes > 100) break; newVal += ch; total += chBytes; } if (type === 'add') { this.addParams.content = newVal; } else { this.editParams.content = newVal; } bytes = total; } else { this.isOverLimit = false; if (type === 'add') { this.addParams.content = val; } else { this.editParams.content = val; } } this.byteCount = bytes; }, handelTime(time) { return `${time.split("T")[0]} ${time.split("T")[1]}` } } }