index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="关键字" prop="keyword">
  5. <el-input
  6. v-model="queryParams.keyword"
  7. placeholder="请输入关键字"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <!-- <el-form-item label="类型" prop="type">-->
  14. <!-- <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">-->
  15. <!-- <el-option-->
  16. <!-- v-for="dict in typeOptions"-->
  17. <!-- :key="dict.dictValue"-->
  18. <!-- :label="dict.dictLabel"-->
  19. <!-- :value="dict.dictValue"-->
  20. <!-- />-->
  21. <!-- </el-select>-->
  22. <!-- </el-form-item>-->
  23. <!-- <el-form-item label="所属公司" prop="companyId">-->
  24. <!-- <el-select filterable v-model="queryParams.companyId" placeholder="请选择所属公司" clearable size="small">-->
  25. <!-- <el-option-->
  26. <!-- v-for="item in companys"-->
  27. <!-- :key="item.companyId"-->
  28. <!-- :label="item.companyName"-->
  29. <!-- :value="item.companyId"-->
  30. <!-- />-->
  31. <!-- </el-select>-->
  32. <!-- </el-form-item>-->
  33. <el-form-item>
  34. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['system:keyword:list']">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. plain
  43. icon="el-icon-plus"
  44. size="mini"
  45. @click="handleAdd"
  46. v-hasPermi="['system:keyword:add']"
  47. >新增</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['system:keyword:edit']"
  58. >修改</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="danger"
  63. plain
  64. icon="el-icon-delete"
  65. size="mini"
  66. :disabled="multiple"
  67. @click="handleDelete"
  68. v-hasPermi="['system:keyword:remove']"
  69. >删除</el-button>
  70. </el-col>
  71. <!-- <el-col :span="1.5">-->
  72. <!-- <el-button-->
  73. <!-- type="warning"-->
  74. <!-- plain-->
  75. <!-- icon="el-icon-download"-->
  76. <!-- size="mini"-->
  77. <!-- :loading="exportLoading"-->
  78. <!-- @click="handleExport"-->
  79. <!-- v-hasPermi="['system:keyword:export']"-->
  80. <!-- >导出</el-button>-->
  81. <!-- </el-col>-->
  82. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  83. </el-row>
  84. <el-table border v-loading="loading" :data="keywordList" @selection-change="handleSelectionChange">
  85. <el-table-column type="selection" width="55" align="center" />
  86. <el-table-column label="关键字" align="center" prop="keyword" />
  87. <!-- <el-table-column label="类型" align="center" prop="typeName" />-->
  88. <!-- <el-table-column label="所属公司" align="center" prop="companyName" />-->
  89. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  90. <template slot-scope="scope">
  91. <el-button
  92. size="mini"
  93. type="text"
  94. icon="el-icon-edit"
  95. @click="handleUpdate(scope.row)"
  96. v-hasPermi="['system:keyword:edit']"
  97. >修改</el-button>
  98. <el-button
  99. size="mini"
  100. type="text"
  101. icon="el-icon-delete"
  102. @click="handleDelete(scope.row)"
  103. v-hasPermi="['system:keyword:remove']"
  104. >删除</el-button>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. <pagination
  109. v-show="total>0"
  110. :total="total"
  111. :page.sync="queryParams.pageNum"
  112. :limit.sync="queryParams.pageSize"
  113. @pagination="getList"
  114. />
  115. <!-- 添加或修改关键字对话框 -->
  116. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  117. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  118. <el-form-item label="关键字" prop="keyword">
  119. <el-input v-model="form.keyword" placeholder="请输入关键字" />
  120. </el-form-item>
  121. <!-- <el-form-item label="类型" prop="type">-->
  122. <!-- <el-select v-model="form.type" placeholder="请选择类型">-->
  123. <!-- <el-option-->
  124. <!-- v-for="dict in typeOptions"-->
  125. <!-- :key="dict.dictValue"-->
  126. <!-- :label="dict.dictLabel"-->
  127. <!-- :value="dict.dictValue"-->
  128. <!-- />-->
  129. <!-- </el-select>-->
  130. <!-- </el-form-item>-->
  131. <!-- <el-form-item label="所属公司" prop="companyId">-->
  132. <!-- <el-select filterable v-model="form.companyId" placeholder="请选择所属公司">-->
  133. <!-- <el-option-->
  134. <!-- v-for="item in companys"-->
  135. <!-- :key="item.companyId"-->
  136. <!-- :label="item.companyName"-->
  137. <!-- :value="item.companyId"-->
  138. <!-- />-->
  139. <!-- </el-select>-->
  140. <!-- </el-form-item>-->
  141. </el-form>
  142. <div slot="footer" class="dialog-footer">
  143. <el-button type="primary" @click="submitForm">确 定</el-button>
  144. <el-button @click="cancel">取 消</el-button>
  145. </div>
  146. </el-dialog>
  147. </div>
  148. </template>
  149. <script>
  150. import { listKeyword, getKeyword, delKeyword, addKeyword, updateKeyword, exportKeyword } from "@/api/system/keyword";
  151. // import { allList } from "@/api/system/dict/data";
  152. import { getCompanyList } from "@/api/company/companyUser";
  153. export default {
  154. name: "Keyword",
  155. data() {
  156. return {
  157. // 遮罩层
  158. loading: true,
  159. // 导出遮罩层
  160. exportLoading: false,
  161. // 选中数组
  162. ids: [],
  163. // 非单个禁用
  164. single: true,
  165. // 非多个禁用
  166. multiple: true,
  167. // 显示搜索条件
  168. showSearch: true,
  169. // 总条数
  170. total: 0,
  171. // 关键字表格数据
  172. keywordList: [],
  173. // 弹出层标题
  174. title: "",
  175. // 是否显示弹出层
  176. open: false,
  177. // 类型选项
  178. typeOptions: [],
  179. // 公司列表
  180. companys: [],
  181. // 查询参数
  182. queryParams: {
  183. pageNum: 1,
  184. pageSize: 10,
  185. keyword: null,
  186. type: null,
  187. companyId: null,
  188. },
  189. // 表单参数
  190. form: {},
  191. // 表单校验
  192. rules: {
  193. }
  194. };
  195. },
  196. created() {
  197. this.getList();
  198. // this.getTypeOptions();
  199. this.getCompanyOptions();
  200. },
  201. methods: {
  202. /** 查询关键字列表 */
  203. getList() {
  204. this.loading = true;
  205. listKeyword(this.queryParams).then(response => {
  206. this.keywordList = response.rows;
  207. this.total = response.total;
  208. this.loading = false;
  209. });
  210. },
  211. // 取消按钮
  212. cancel() {
  213. this.open = false;
  214. this.reset();
  215. },
  216. // 表单重置
  217. reset() {
  218. this.form = {
  219. keywordId: null,
  220. keyword: null,
  221. type: null,
  222. companyId: null,
  223. createTime: null,
  224. updateTime: null
  225. };
  226. this.resetForm("form");
  227. },
  228. /** 搜索按钮操作 */
  229. handleQuery() {
  230. this.queryParams.pageNum = 1;
  231. this.getList();
  232. },
  233. /** 重置按钮操作 */
  234. resetQuery() {
  235. this.resetForm("queryForm");
  236. this.handleQuery();
  237. },
  238. // 多选框选中数据
  239. handleSelectionChange(selection) {
  240. this.ids = selection.map(item => item.keywordId)
  241. this.single = selection.length!==1
  242. this.multiple = !selection.length
  243. },
  244. /** 新增按钮操作 */
  245. handleAdd() {
  246. this.reset();
  247. this.open = true;
  248. this.title = "添加关键字";
  249. },
  250. /** 修改按钮操作 */
  251. handleUpdate(row) {
  252. this.reset();
  253. const keywordId = row.keywordId || this.ids
  254. getKeyword(keywordId).then(response => {
  255. this.form = response.data;
  256. // 强制把type转成字符串
  257. this.form.type = String(response.data.type);
  258. this.open = true;
  259. this.title = "修改关键字";
  260. });
  261. },
  262. /** 提交按钮 */
  263. submitForm() {
  264. this.$refs["form"].validate(valid => {
  265. if (valid) {
  266. // 提交前移除临时属性
  267. const submitData = { ...this.form };
  268. delete submitData.typeName;
  269. delete submitData.companyName;
  270. if (this.form.keywordId != null) {
  271. updateKeyword(submitData).then(response => {
  272. this.msgSuccess("修改成功");
  273. this.open = false;
  274. this.getList();
  275. });
  276. } else {
  277. addKeyword(submitData).then(response => {
  278. this.msgSuccess("新增成功");
  279. this.open = false;
  280. this.getList();
  281. });
  282. }
  283. }
  284. });
  285. },
  286. /** 删除按钮操作 */
  287. handleDelete(row) {
  288. const keywordIds = row.keywordId || this.ids;
  289. this.$confirm('是否确认删除该数据?', "警告", {
  290. confirmButtonText: "确定",
  291. cancelButtonText: "取消",
  292. type: "warning"
  293. }).then(function() {
  294. return delKeyword(keywordIds);
  295. }).then(() => {
  296. this.getList();
  297. this.msgSuccess("删除成功");
  298. }).catch(() => {});
  299. },
  300. /** 导出按钮操作 */
  301. handleExport() {
  302. const queryParams = this.queryParams;
  303. this.$confirm('是否确认导出所有关键字数据项?', "警告", {
  304. confirmButtonText: "确定",
  305. cancelButtonText: "取消",
  306. type: "warning"
  307. }).then(() => {
  308. this.exportLoading = true;
  309. return exportKeyword(queryParams);
  310. }).then(response => {
  311. this.download(response.msg);
  312. this.exportLoading = false;
  313. }).catch(() => {});
  314. },
  315. /** 获取类型选项 */
  316. // getTypeOptions() {
  317. // allList({ dictType: "keyword_type" }).then(response => {
  318. // this.typeOptions = response.data;
  319. // });
  320. // },
  321. /** 获取公司选项 */
  322. getCompanyOptions() {
  323. getCompanyList().then(response => {
  324. this.companys = response.data;
  325. });
  326. }
  327. }
  328. };
  329. </script>