index.vue 7.4 KB

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