index.vue 8.2 KB

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