index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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="createdAt" label-width="120px">
  14. <el-date-picker clearable size="small"
  15. v-model="queryParams.createdAt"
  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="createdAt" width="180">
  77. <template slot-scope="scope">
  78. <span>{{ parseTime(scope.row.createdAt, '{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-item label="敏感词添加时间" prop="createdAt" >
  114. <el-date-picker clearable size="small"
  115. v-model="form.createdAt"
  116. type="date"
  117. value-format="yyyy-MM-dd"
  118. placeholder="选择敏感词添加时间">
  119. </el-date-picker>
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button type="primary" @click="submitForm">确 定</el-button>
  124. <el-button @click="cancel">取 消</el-button>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { listWords, getWords, delWords, addWords, updateWords, exportWords } from "@/api/live/words";
  131. export default {
  132. name: "Words",
  133. data() {
  134. return {
  135. // 遮罩层
  136. loading: true,
  137. // 导出遮罩层
  138. exportLoading: false,
  139. // 选中数组
  140. ids: [],
  141. // 非单个禁用
  142. single: true,
  143. // 非多个禁用
  144. multiple: true,
  145. // 显示搜索条件
  146. showSearch: true,
  147. // 总条数
  148. total: 0,
  149. // 直播间敏感词过滤表格数据
  150. wordsList: [],
  151. // 弹出层标题
  152. title: "",
  153. // 是否显示弹出层
  154. open: false,
  155. // 查询参数
  156. queryParams: {
  157. pageNum: 1,
  158. pageSize: 10,
  159. word: null,
  160. createdAt: null
  161. },
  162. // 表单参数
  163. form: {},
  164. // 表单校验
  165. rules: {
  166. word: [
  167. { required: true, message: "需要过滤的敏感词不能为空", trigger: "blur" }
  168. ],
  169. }
  170. };
  171. },
  172. created() {
  173. this.getList();
  174. },
  175. methods: {
  176. /** 查询直播间敏感词过滤列表 */
  177. getList() {
  178. this.loading = true;
  179. listWords(this.queryParams).then(response => {
  180. this.wordsList = response.rows;
  181. this.total = response.total;
  182. this.loading = false;
  183. });
  184. },
  185. // 取消按钮
  186. cancel() {
  187. this.open = false;
  188. this.reset();
  189. },
  190. // 表单重置
  191. reset() {
  192. this.form = {
  193. wordId: null,
  194. word: null,
  195. createdAt: null
  196. };
  197. this.resetForm("form");
  198. },
  199. /** 搜索按钮操作 */
  200. handleQuery() {
  201. this.queryParams.pageNum = 1;
  202. this.getList();
  203. },
  204. /** 重置按钮操作 */
  205. resetQuery() {
  206. this.resetForm("queryForm");
  207. this.handleQuery();
  208. },
  209. // 多选框选中数据
  210. handleSelectionChange(selection) {
  211. this.ids = selection.map(item => item.wordId)
  212. this.single = selection.length!==1
  213. this.multiple = !selection.length
  214. },
  215. /** 新增按钮操作 */
  216. handleAdd() {
  217. this.reset();
  218. this.open = true;
  219. this.title = "添加直播间敏感词过滤";
  220. },
  221. /** 修改按钮操作 */
  222. handleUpdate(row) {
  223. this.reset();
  224. const wordId = row.wordId || this.ids
  225. getWords(wordId).then(response => {
  226. this.form = response.data;
  227. this.open = true;
  228. this.title = "修改直播间敏感词过滤";
  229. });
  230. },
  231. /** 提交按钮 */
  232. submitForm() {
  233. this.$refs["form"].validate(valid => {
  234. if (valid) {
  235. if (this.form.wordId != null) {
  236. updateWords(this.form).then(response => {
  237. this.msgSuccess("修改成功");
  238. this.open = false;
  239. this.getList();
  240. });
  241. } else {
  242. addWords(this.form).then(response => {
  243. this.msgSuccess("新增成功");
  244. this.open = false;
  245. this.getList();
  246. });
  247. }
  248. }
  249. });
  250. },
  251. /** 删除按钮操作 */
  252. handleDelete(row) {
  253. const wordIds = row.wordId || this.ids;
  254. this.$confirm('是否确认删除直播间敏感词过滤编号为"' + wordIds + '"的数据项?', "警告", {
  255. confirmButtonText: "确定",
  256. cancelButtonText: "取消",
  257. type: "warning"
  258. }).then(function() {
  259. return delWords(wordIds);
  260. }).then(() => {
  261. this.getList();
  262. this.msgSuccess("删除成功");
  263. }).catch(() => {});
  264. },
  265. /** 导出按钮操作 */
  266. handleExport() {
  267. const queryParams = this.queryParams;
  268. this.$confirm('是否确认导出所有直播间敏感词过滤数据项?', "警告", {
  269. confirmButtonText: "确定",
  270. cancelButtonText: "取消",
  271. type: "warning"
  272. }).then(() => {
  273. this.exportLoading = true;
  274. return exportWords(queryParams);
  275. }).then(response => {
  276. this.download(response.msg);
  277. this.exportLoading = false;
  278. }).catch(() => {});
  279. }
  280. }
  281. };
  282. </script>