blackWordList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <!-- 友情链接列表 -->
  3. <div>
  4. <div class="title">
  5. <el-row>
  6. <el-col :span="6" class="left">
  7. <div class="searchBox">
  8. <div class="searchTitle">违禁词名称</div>
  9. <el-input v-model="name" placeholder="请输入违禁词名称"></el-input>
  10. </div>
  11. </el-col>
  12. <el-col :span="10" class="right">
  13. <div class="btnList">
  14. <button class="search" @click="goSearch">搜索</button>
  15. <button class="reset" @click="reset">重置</button>
  16. </div>
  17. </el-col>
  18. </el-row>
  19. </div>
  20. <!--表格内容 start------------------------------------------------------------>
  21. <div class="layerBox">
  22. <tableTitle :name="tableDivTitle" />
  23. <button class="btn" @click="addBlackWord">添加违禁词</button>
  24. <el-row>
  25. <template>
  26. <el-table class="my-table" :data="tableData" style="width: 100%">
  27. <el-table-column fixed prop="id" label="编号" width="70">
  28. </el-table-column>
  29. <el-table-column prop="name" label="违禁词名称" width="400">
  30. </el-table-column>
  31. <el-table-column prop="created_at" label="创建时间">
  32. </el-table-column>
  33. <el-table-column prop="updated_at" label="修改时间">
  34. </el-table-column>
  35. <el-table-column fixed="right" header-align="center" label="操作" width="220">
  36. <template slot-scope="scope">
  37. <div class="listBtnBox">
  38. <div class="listDeleteBtn" @click="deleteRow(scope.row.name, scope.row)">
  39. <i class="el-icon-delete"></i>删除
  40. </div>
  41. <div class="listEditBtn" @click="goEdit(scope.row.id, scope.row)">
  42. <i class="el-icon-edit-outline"></i>编辑
  43. </div>
  44. </div>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </template>
  49. </el-row>
  50. </div>
  51. <!--分页 start------------------------------------------------------------>
  52. <div class="alignBox">
  53. <el-row>
  54. <el-col :span="24">
  55. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  56. :current-page="page" :page-size="pageSize" layout="total, prev, pager, next, jumper"
  57. :total="total">
  58. </el-pagination>
  59. </el-col>
  60. </el-row>
  61. </div>
  62. <!--分页 end------------------------------------------------------------>
  63. <!--表格内容 end------------------------------------------------------------>
  64. <!-- 弹出框 start------------------------------------------------------------>
  65. <el-dialog :title="dialogName" :visible.sync="dialogTableVisible" width="50%" :close-on-click-modal="false">
  66. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  67. <div class="dialogText">
  68. <el-form-item label="违禁词名称:" prop="name">
  69. <el-input v-model="ruleForm.name" placeholder="请输入违禁词名称"></el-input>
  70. </el-form-item>
  71. </div>
  72. <div class="dialogBtn">
  73. <el-button type="info" @click="cancelForm">取消</el-button>
  74. <el-button type="primary" @click="submitForm">提交</el-button>
  75. </div>
  76. </el-form>
  77. </el-dialog>
  78. <!-- 弹出框 end------------------------------------------------------------>
  79. </div>
  80. </template>
  81. <script>
  82. //表格标题
  83. import tableTitle from './components/blogroll/tableTitle.vue';
  84. //引入公用样式
  85. import '@/styles/global.less';
  86. // 引入api
  87. import { getBlackWordList, addBlackWord, delBlackWord, upBlackWord } from '@/api/blackWord.js'
  88. export default {
  89. components: {
  90. tableTitle,//表格标题
  91. },
  92. data() {
  93. const validateEmpty = (rule, value, callback) => {
  94. if (value.length == 0) {
  95. callback(new Error('该项不能为空!'))
  96. } else {
  97. callback()
  98. }
  99. }
  100. return {
  101. tableDivTitle: "违禁词列表", //表格标题
  102. name: '', // 违禁词名称
  103. // 分页器相关
  104. total: 0,
  105. page: 1,
  106. pageSize: 10,
  107. //表格相关
  108. tableData: [],
  109. //弹出框相关
  110. dialogTableVisible: false, //是否显示
  111. dialogName: '', //弹框标题名
  112. value: [],
  113. list: [],
  114. // 图片相关
  115. formLabelWidth: '120px',//表单的长度
  116. id:'',
  117. //表单相关
  118. ruleForm: {
  119. name: '', //违禁词名称
  120. },
  121. rules: { //规则
  122. name: [{ required: true, trigger: 'blur', validator: validateEmpty }], //违禁词名称
  123. },
  124. }
  125. },
  126. methods: {
  127. getData() {
  128. getBlackWordList({
  129. page: this.page,
  130. pageSize: this.pageSize,
  131. name: this.name
  132. }).then(data => {
  133. console.log(data);
  134. this.tableData = data.data.rows
  135. this.total = data.data.count
  136. })
  137. },
  138. //1.2 删除内容
  139. deleteRow(name, val) {
  140. this.$confirm('注意:您是否确定删除该违禁词?', '提示', {
  141. confirmButtonText: '确定',
  142. cancelButtonText: '取消',
  143. }).then(() => {
  144. delBlackWord({
  145. name: name,
  146. }).then(data => {
  147. console.log(data);
  148. if (data.code == 200) {
  149. this.$message({
  150. type: 'success',
  151. message: '删除成功!'
  152. });
  153. this.getData()
  154. } else if (data.code == 0) {
  155. this.$message({
  156. type: 'error',
  157. message: data.message
  158. });
  159. }
  160. })
  161. }).catch(() => {
  162. this.$message({
  163. type: 'warning',
  164. message: '已取消'
  165. });
  166. });
  167. },
  168. //1.3 列表内容分页
  169. //直接跳转
  170. handleSizeChange(val) {
  171. this.page = val;
  172. this.getData();
  173. },
  174. //1.4 点击分页
  175. handleCurrentChange(val) {
  176. this.page = val;
  177. this.getData();
  178. },
  179. // 1.5 搜索按钮
  180. goSearch() {
  181. this.page = 1
  182. this.getData()
  183. },
  184. //1.6 重置按钮
  185. reset() {
  186. this.name = ''
  187. this.getData()
  188. },
  189. //列表和分页相关 end ------------------------------------------------------------>
  190. //1.7 添加
  191. addBlackWord() {
  192. this.dialogTableVisible = true //弹窗是否显示
  193. this.dialogName = "添加" //弹窗名称
  194. this.ruleForm.name = ''
  195. },
  196. // 弹出层相关方法
  197. // 提交表单
  198. submitForm() {
  199. // 添加
  200. if (this.dialogName == "添加") {
  201. addBlackWord({
  202. name: this.ruleForm.name,
  203. }).then(data => {
  204. console.log(data);
  205. if (data.code == 200) {
  206. this.$message({
  207. message: "添加成功",
  208. type: 'success'
  209. });
  210. this.dialogTableVisible = false
  211. this.getData()
  212. } else {
  213. this.$message.error(data.message)
  214. }
  215. })
  216. }
  217. if (this.dialogName == "编辑") {
  218. upBlackWord({
  219. id: this.id,
  220. name: this.ruleForm.name,
  221. }).then(data => {
  222. console.log(data);
  223. if (data.code == 200) {
  224. this.$message({
  225. message: "修改成功",
  226. type: 'success'
  227. });
  228. this.dialogTableVisible = false
  229. this.getData()
  230. } else {
  231. this.$message.error(data.message)
  232. }
  233. })
  234. }
  235. },
  236. //取消添加或编辑
  237. cancelForm() {
  238. this.dialogTableVisible = false
  239. },
  240. goEdit(id, val) {
  241. this.dialogTableVisible = true //弹框显示
  242. this.dialogName = "编辑" //弹框名字
  243. this.id = id //活动id
  244. this.ruleForm.name = val.name //违规词名称
  245. },
  246. },
  247. mounted() {
  248. //获取网站列表数据
  249. this.getData()
  250. }
  251. }
  252. </script>
  253. <style scoped lang="less">
  254. .title {
  255. margin: 30px 30px 20px 30px;
  256. padding: 30px 30px 40px 30px;
  257. background-color: #fff;
  258. border-radius: 20px 20px 20px 20px;
  259. border: 1px solid #E9EDF7;
  260. .left {
  261. float: left;
  262. }
  263. .right {
  264. float: right;
  265. }
  266. .searchBox {
  267. .searchTitle {
  268. padding-bottom: 10px;
  269. font-family: Microsoft YaHei, Microsoft YaHei;
  270. font-weight: 400;
  271. font-size: 14px;
  272. color: #999999;
  273. line-height: 16px;
  274. }
  275. .el-select {
  276. width: 85%;
  277. display: inline-block;
  278. position: relative;
  279. }
  280. }
  281. .btnList {
  282. float: right;
  283. padding-top: 28px;
  284. button {
  285. width: 120px;
  286. height: 38px;
  287. border: none;
  288. border-radius: 8px;
  289. // padding: 0 30px;
  290. }
  291. .search {
  292. background-color: #5570f1;
  293. color: #fff;
  294. margin-right: 20px;
  295. }
  296. .reset {
  297. font-family: Microsoft YaHei, Microsoft YaHei;
  298. font-weight: 400;
  299. font-size: 16px;
  300. color: #333333;
  301. background: #F5F7FB;
  302. border-radius: 8px 8px 8px 8px;
  303. border: 1px solid rgba(85, 112, 241, 0.11);
  304. }
  305. }
  306. }
  307. .layerBox {
  308. padding: 30px 20px;
  309. position: relative;
  310. .btn {
  311. position: absolute;
  312. top: 30px;
  313. right: 20px;
  314. height: 38px;
  315. color: #fff;
  316. background-color: #5570f1;
  317. border: none;
  318. border-radius: 8px;
  319. padding: 8px 28px 9px;
  320. box-sizing: border-box;
  321. }
  322. .listBtnBox {
  323. justify-content: left;
  324. }
  325. .listDeleteBtn,
  326. .listEditBtn,
  327. .listLookBtn {
  328. margin-left: 0px;
  329. padding-left: 0px;
  330. margin-right: 20px;
  331. width: 76px;
  332. height: 36px;
  333. line-height: 36px;
  334. }
  335. .listLookBtn {
  336. text-align: center;
  337. border-radius: 8px;
  338. cursor: pointer;
  339. color: #55b5f1;
  340. background-color: rgba(85, 181, 241, 0.16);
  341. >i {
  342. padding-right: 8px;
  343. }
  344. }
  345. .uploadImage {
  346. width: 130px;
  347. }
  348. // from表单中每条数据的下外边距
  349. ::v-deep .el-form-item {
  350. margin-bottom: 50px;
  351. }
  352. //下拉框宽度
  353. ::v-deep .el-select {
  354. width: 100%;
  355. }
  356. ::v-deep .el-input--medium,
  357. ::v-deep .el-form-item__label {
  358. line-height: 36px;
  359. font-size: 16px;
  360. }
  361. }
  362. // 弹出层内容
  363. .dialogText {
  364. margin: 0 7px 0 3px;
  365. padding-top: 20px;
  366. padding-bottom: 1px;
  367. padding: 20px 60px 1px 20px;
  368. background-color: #f5f7fb;
  369. // from表单中每条数据的下外边距
  370. ::v-deep .el-form-item {
  371. margin-bottom: 50px;
  372. }
  373. //下拉框宽度
  374. ::v-deep .el-select {
  375. width: 100%;
  376. }
  377. //图片的宽高
  378. ::v-deep .avatar {
  379. width: 140px;
  380. height: auto;
  381. }
  382. .keywords {
  383. position: relative;
  384. i {
  385. position: absolute;
  386. top: 0;
  387. left: -15px;
  388. }
  389. }
  390. }
  391. // 弹出层按钮
  392. .dialogBtn {
  393. text-align: center;
  394. margin: 50px auto 20px;
  395. ::v-deep .avatar {
  396. width: 140px;
  397. height: 50px;
  398. display: block;
  399. }
  400. button {
  401. width: 184px;
  402. padding: 16px;
  403. font-family: Microsoft YaHei, Microsoft YaHei;
  404. font-weight: 400;
  405. font-size: 20px;
  406. border: none;
  407. border-radius: 12px 12px 12px 12px;
  408. }
  409. // 取消
  410. .cancel {
  411. color: #333333;
  412. background-color: #f5f7fb;
  413. border: 2px solid rgba(85, 112, 241, 0.11);
  414. }
  415. // 提交
  416. .submit {
  417. color: #fff;
  418. background-color: #5570F1;
  419. margin-left: 40px;
  420. }
  421. }
  422. </style>