index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="app-container live-page">
  3. <div class="live-page__header">
  4. <h2 class="live-page__title">敏感词</h2>
  5. </div>
  6. <div class="live-panel" v-show="showSearch">
  7. <el-form class="live-search-form" :model="queryParams" ref="queryForm" :inline="true" label-width="80px">
  8. <el-form-item label="敏感词" prop="word">
  9. <el-input
  10. v-model="queryParams.word"
  11. placeholder="请输入需要过滤的敏感词"
  12. clearable
  13. size="small"
  14. @keyup.enter.native="handleQuery"
  15. />
  16. </el-form-item>
  17. <el-form-item label="敏感词添加时间" prop="createTime" label-width="120px">
  18. <el-date-picker clearable size="small"
  19. v-model="queryParams.createTime"
  20. type="date"
  21. value-format="yyyy-MM-dd"
  22. placeholder="选择敏感词添加时间">
  23. </el-date-picker>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. <div class="live-panel live-panel--table">
  32. <el-row :gutter="10" class="mb8">
  33. <el-col :span="1.5">
  34. <el-button
  35. type="primary"
  36. plain
  37. icon="el-icon-plus"
  38. size="mini"
  39. @click="handleAdd"
  40. v-hasPermi="['live:words:add']"
  41. >新增</el-button>
  42. </el-col>
  43. <el-col :span="1.5">
  44. <el-button
  45. type="success"
  46. plain
  47. icon="el-icon-edit"
  48. size="mini"
  49. :disabled="single"
  50. @click="handleUpdate"
  51. v-hasPermi="['live:words:edit']"
  52. >修改</el-button>
  53. </el-col>
  54. <el-col :span="1.5">
  55. <el-button
  56. type="danger"
  57. plain
  58. icon="el-icon-delete"
  59. size="mini"
  60. :disabled="multiple"
  61. @click="handleDelete"
  62. v-hasPermi="['live:words:remove']"
  63. >删除</el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button
  67. type="warning"
  68. plain
  69. icon="el-icon-download"
  70. size="mini"
  71. :loading="exportLoading"
  72. @click="handleExport"
  73. v-hasPermi="['live:words:export']"
  74. >导出</el-button>
  75. </el-col>
  76. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  77. </el-row>
  78. <el-table border v-loading="loading" :data="wordsList" @selection-change="handleSelectionChange">
  79. <el-table-column type="selection" width="55" align="center" />
  80. <el-table-column label="敏感词唯一标识" align="center" prop="wordId" />
  81. <el-table-column label="需要过滤的敏感词" align="center" prop="word" />
  82. <el-table-column label="敏感词添加时间" align="center" prop="createTime" width="180">
  83. <template slot-scope="scope">
  84. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  88. <template slot-scope="scope">
  89. <el-button
  90. size="mini"
  91. type="text"
  92. icon="el-icon-edit"
  93. @click="handleUpdate(scope.row)"
  94. v-hasPermi="['live:words:edit']"
  95. >修改</el-button>
  96. <el-button
  97. size="mini"
  98. type="text"
  99. icon="el-icon-delete"
  100. @click="handleDelete(scope.row)"
  101. v-hasPermi="['live:words:remove']"
  102. >删除</el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. <pagination
  107. v-show="total>0"
  108. :total="total"
  109. :page.sync="queryParams.pageNum"
  110. :limit.sync="queryParams.pageSize"
  111. @pagination="getList"
  112. />
  113. </div>
  114. <!-- 添加或修改直播间敏感词过滤对话框 -->
  115. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  116. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  117. <el-form-item label="敏感词" prop="word">
  118. <el-input v-model="form.word" placeholder="请输入需要过滤的敏感词" />
  119. </el-form-item>
  120. </el-form>
  121. <div slot="footer" class="dialog-footer">
  122. <el-button type="primary" @click="submitForm">确 定</el-button>
  123. <el-button @click="cancel">取 消</el-button>
  124. </div>
  125. </el-dialog>
  126. </div>
  127. </template>
  128. <script>
  129. import {listWords, getWords, delWords, addWords, updateWords, exportWords} from "@/api/live/words";
  130. export default {
  131. name: "Words",
  132. data() {
  133. return {
  134. // 遮罩层
  135. loading: true,
  136. // 导出遮罩层
  137. exportLoading: false,
  138. // 选中数组
  139. ids: [],
  140. // 非单个禁用
  141. single: true,
  142. // 非多个禁用
  143. multiple: true,
  144. // 显示搜索条件
  145. showSearch: true,
  146. // 总条数
  147. total: 0,
  148. // 直播间敏感词过滤表格数据
  149. wordsList: [],
  150. // 弹出层标题
  151. title: "",
  152. // 是否显示弹出层
  153. open: false,
  154. // 查询参数
  155. queryParams: {
  156. pageNum: 1,
  157. pageSize: 10,
  158. word: null,
  159. createTime: null
  160. },
  161. // 表单参数
  162. form: {},
  163. // 表单校验
  164. rules: {
  165. word: [
  166. { required: true, message: "需要过滤的敏感词不能为空", trigger: "blur" }
  167. ],
  168. }
  169. };
  170. },
  171. created() {
  172. this.getList();
  173. },
  174. methods: {
  175. /** 查询直播间敏感词过滤列表 */
  176. getList() {
  177. this.loading = true;
  178. listWords(this.queryParams).then(response => {
  179. this.wordsList = response.rows;
  180. this.total = response.total;
  181. this.loading = false;
  182. });
  183. },
  184. // 取消按钮
  185. cancel() {
  186. this.open = false;
  187. this.reset();
  188. },
  189. // 表单重置
  190. reset() {
  191. this.form = {
  192. wordId: null,
  193. word: null,
  194. createTime: null
  195. };
  196. this.resetForm("form");
  197. },
  198. /** 搜索按钮操作 */
  199. handleQuery() {
  200. this.queryParams.pageNum = 1;
  201. this.getList();
  202. },
  203. /** 重置按钮操作 */
  204. resetQuery() {
  205. this.resetForm("queryForm");
  206. this.handleQuery();
  207. },
  208. // 多选框选中数据
  209. handleSelectionChange(selection) {
  210. this.ids = selection.map(item => item.wordId)
  211. this.single = selection.length!==1
  212. this.multiple = !selection.length
  213. },
  214. /** 新增按钮操作 */
  215. handleAdd() {
  216. this.reset();
  217. this.open = true;
  218. this.title = "添加直播间敏感词过滤";
  219. },
  220. /** 修改按钮操作 */
  221. handleUpdate(row) {
  222. this.reset();
  223. const wordId = row.wordId || this.ids
  224. getWords(wordId).then(response => {
  225. this.form = response.data;
  226. this.open = true;
  227. this.title = "修改直播间敏感词过滤";
  228. });
  229. },
  230. /** 提交按钮 */
  231. submitForm() {
  232. this.$refs["form"].validate(valid => {
  233. if (valid) {
  234. if (this.form.wordId != null) {
  235. updateWords(this.form).then(response => {
  236. this.msgSuccess("修改成功");
  237. this.open = false;
  238. this.getList();
  239. });
  240. } else {
  241. addWords(this.form).then(response => {
  242. this.msgSuccess("新增成功");
  243. this.open = false;
  244. this.getList();
  245. });
  246. }
  247. }
  248. });
  249. },
  250. /** 删除按钮操作 */
  251. handleDelete(row) {
  252. const wordIds = row.wordId || this.ids;
  253. this.$confirm('是否确认删除直播间敏感词过滤编号为"' + wordIds + '"的数据项?', "警告", {
  254. confirmButtonText: "确定",
  255. cancelButtonText: "取消",
  256. type: "warning"
  257. }).then(function() {
  258. return delWords(wordIds);
  259. }).then(() => {
  260. this.getList();
  261. this.msgSuccess("删除成功");
  262. }).catch(() => {});
  263. },
  264. /** 导出按钮操作 */
  265. handleExport() {
  266. const queryParams = this.queryParams;
  267. this.$confirm('是否确认导出所有直播间敏感词过滤数据项?', "警告", {
  268. confirmButtonText: "确定",
  269. cancelButtonText: "取消",
  270. type: "warning"
  271. }).then(() => {
  272. this.exportLoading = true;
  273. return exportWords(queryParams);
  274. }).then(response => {
  275. this.download(response.msg);
  276. this.exportLoading = false;
  277. }).catch(() => {});
  278. }
  279. }
  280. };
  281. </script>