天波用户运营管理后台系统
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

442 行
15KB

  1. <!--
  2. * @Date: 2021-11-30 09:44:24
  3. * @LastEditors: JinxuChen
  4. * @LastEditTime: 2021-12-23 11:21:28
  5. * @FilePath: \GpsCardAdmin\src\views\off-limits-manage\alarm-recognition\index.vue
  6. * @description:
  7. -->
  8. <template>
  9. <div class="app-container">
  10. <div class="filter-container">
  11. <el-button
  12. class="filter-item"
  13. style="margin-left: 10px;"
  14. type="primary"
  15. icon="el-icon-circle-plus"
  16. @click="onAdd"
  17. >添加</el-button>
  18. <el-button
  19. v-show="false"
  20. class="filter-item"
  21. style="margin-left: 10px;"
  22. type="primary"
  23. icon="el-icon-folder-add"
  24. @click="onImportBatch"
  25. >批量导入</el-button>
  26. <!-- 下拉 -->
  27. <!-- 类别 -->
  28. <el-select
  29. v-model="model"
  30. placeholder="类别"
  31. style="width: 130px; margin-left: 10px;"
  32. filterable
  33. @change="outSelecChange"
  34. @clear="onClear"
  35. clearable
  36. v-show="false"
  37. >
  38. <el-option
  39. v-for="item in modelOptions"
  40. :key="item.value"
  41. :label="item.label"
  42. :value="item.value"
  43. class="filter-item"
  44. ></el-option>
  45. </el-select>
  46. <!-- 搜索 -->
  47. <el-input
  48. v-model="searchValue"
  49. :placeholder="placeholder"
  50. style="width: 200px; margin-left: 10px;"
  51. class="filter-item"
  52. @keyup.enter.native="onSearch"
  53. clearable
  54. />
  55. <el-button
  56. class="filter-item"
  57. style="margin-left: 10px;"
  58. type="primary"
  59. icon="el-icon-search"
  60. @click="onSearch"
  61. >搜索</el-button>
  62. </div>
  63. <TTable :tableData="list" :columns="columns" @update="onUpdate" @delete="onDelete"></TTable>
  64. <!-- 分页 -->
  65. <pagination
  66. v-show="total>0"
  67. :total="total"
  68. :page.sync="page"
  69. ref="pages"
  70. :limit.sync="limit"
  71. @pagination="getList"
  72. />
  73. <el-dialog :visible.sync="dialogPvVisible" :title="dialogTitle">
  74. <el-form
  75. ref="form"
  76. :rules="formRules"
  77. :model="form"
  78. label-position="left"
  79. label-width="70px"
  80. >
  81. <!-- 类型 -->
  82. <el-form-item label="类型" prop="typeRadio" v-show="false">
  83. <el-radio-group v-model="form.typeRadio">
  84. <el-radio :label="1" border>关键字</el-radio>
  85. <el-radio :label="2" border>固定地点</el-radio>
  86. </el-radio-group>
  87. </el-form-item>
  88. <!-- 类别 -->
  89. <el-form-item label="类别" prop="model">
  90. <el-select v-model="form.model" class="filter-item" @change="onSelectChange">
  91. <el-option
  92. v-for="item in formOptions"
  93. :key="item.value"
  94. :label="item.label"
  95. :value="item.value"
  96. />
  97. </el-select>
  98. </el-form-item>
  99. <!-- 内容名称 -->
  100. <el-form-item label="内容名称" prop="content" label-width="80px">
  101. <el-input v-model="form.content" style="width: 100%"/>
  102. </el-form-item>
  103. <!-- 状态 -->
  104. <el-form-item label="状态" prop="status" required>
  105. <el-switch v-model="form.status" active-text="启用" inactive-text="关闭"></el-switch>
  106. </el-form-item>
  107. <!-- 创建时间 -->
  108. <el-form-item label="创建时间" prop="timestamp" v-show="false">
  109. <el-date-picker v-model="form.createTime" type="datetime" />
  110. </el-form-item>
  111. </el-form>
  112. <span slot="footer" class="dialog-footer">
  113. <el-button type="error" @click="dialogPvVisible = false">取消</el-button>
  114. <el-button
  115. type="primary"
  116. :loading="loading"
  117. @click="dialogStatus === 'update' ? update('form') : add('form')"
  118. >确认</el-button>
  119. </span>
  120. </el-dialog>
  121. <el-dialog :visible.sync="dialogUpload">
  122. <upload-excel-component :on-success="handleSuccess" :before-upload="beforeUpload" />
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script>
  127. import TTable from "../../../components/TTable/TTable";
  128. import Pagination from "@/components/Pagination";
  129. import UploadExcelComponent from "@/components/UploadExcel/index.vue";
  130. import APILimits from "@/api/off-limits-manage";
  131. export default {
  132. name: "",
  133. components: { TTable, Pagination, UploadExcelComponent },
  134. data() {
  135. return {
  136. buttonList: [
  137. {
  138. name: "添加",
  139. type: "success",
  140. click: () => {
  141. this.onAdd();
  142. }
  143. },
  144. {
  145. name: "批量导入",
  146. type: "success",
  147. click: () => {
  148. this.onImportBatch();
  149. }
  150. }
  151. ],
  152. type: "",
  153. model: "",
  154. modelOptions: [],
  155. searchValue: "",
  156. columns: [
  157. { prop: "type", title: "类型", fixed: 'left' },
  158. { prop: "model", title: "类别" },
  159. { prop: "content", title: "内容名称" },
  160. { prop: "createTime", title: "创建时间" },
  161. { prop: "status", title: "状态" },
  162. {
  163. action: true,
  164. title: "操作",
  165. actions: [
  166. { fnName: "update", title: "修改", type: "primary", icon: 'el-icon-edit' },
  167. { fnName: "delete", title: "删除", type: "danger", icon: 'el-icon-delete' }
  168. ]
  169. }
  170. ],
  171. list: [],
  172. total: 0,
  173. page: 1,
  174. limit: 10,
  175. dialogPvVisible: false,
  176. dialogStatus: "",
  177. dialogTitle: "修改告警识别内容",
  178. form: {
  179. typeRadio: 1,
  180. model: "",
  181. content: "",
  182. createTime: "",
  183. resource: "",
  184. categoryId: "",
  185. status: true,
  186. id: ""
  187. },
  188. formRules: {
  189. content: [
  190. {
  191. required: true,
  192. message: "请输入内容名称",
  193. trigger: "blur"
  194. }
  195. ],
  196. typeRadio: [
  197. { required: true, message: "请选择类型", trigger: "change" }
  198. ],
  199. model: [
  200. { required: true, message: "请选择类别", trigger: "change" }
  201. ]
  202. },
  203. formOptions: [],
  204. dialogUpload: false,
  205. loading: false,
  206. placeholder: '请输入内容'
  207. };
  208. },
  209. watch: {
  210. model(value) {
  211. if (value === "") {
  212. this.$refs['pages'].currentPage = 1;
  213. this.getList();
  214. }
  215. },
  216. searchValue(value) {
  217. if (value === "") {
  218. this.$refs['pages'].currentPage = 1;
  219. this.getList();
  220. }
  221. }
  222. },
  223. methods: {
  224. // 清空表单
  225. resetForm() {
  226. this.form = {
  227. typeRadio: 1,
  228. model: "",
  229. content: "",
  230. createTime: "",
  231. resource: "",
  232. categoryId: "",
  233. status: true
  234. };
  235. },
  236. // 添加
  237. onAdd() {
  238. this.resetForm();
  239. /* this.form.typeRadio = 1; */
  240. this.dialogTitle = "添加告警识别内容";
  241. this.dialogPvVisible = true;
  242. this.dialogStatus = "add";
  243. this.form.status = true;
  244. this.getAreaCategoryQuery();
  245. },
  246. add(formName) {
  247. let reqBody = {
  248. id: 0,
  249. categoryId: this.form.categoryId,
  250. keyword: this.form.content,
  251. status: this.form.status
  252. };
  253. this.$refs[formName].validate(valid => {
  254. if (valid) {
  255. APILimits.changeRecognition(reqBody).then(res => {
  256. console.log(res);
  257. if (res.code === 0) {
  258. this.dialogPvVisible = false;
  259. this.$message({
  260. message: "增加成功",
  261. type: "success"
  262. });
  263. this.getList();
  264. }
  265. });
  266. } else {
  267. return false;
  268. }
  269. });
  270. },
  271. // 批量导入, ##注意 ,批量导入格式必须跟表格的一样
  272. onImportBatch() {
  273. this.dialogUpload = true;
  274. },
  275. // 搜索
  276. onSearch() {
  277. this.$refs['pages'].currentPage = 1;
  278. this.getList();
  279. },
  280. // 修改
  281. onUpdate(row) {
  282. console.log("row", row);
  283. this.getAreaCategoryQuery();
  284. this.dialogPvVisible = true;
  285. this.dialogStatus = "update";
  286. this.dialogTitle = "修改告警识别内容"; // copy obj
  287. this.form.categoryId = row.categoryId;
  288. this.form.createTime = new Date(this.form.createTime);
  289. this.form.typeRadio = row.kindId;
  290. this.form.model = row.categoryId;
  291. this.form.id = row.id;
  292. this.form.content = row.content;
  293. this.form.status = row.status === '打开' ? true : false;
  294. },
  295. update(formName) {
  296. let reqBody = {
  297. id: this.form.id, //0 是新增 选中的rouw的id是修改
  298. categoryId: this.form.categoryId,
  299. kindId: this.form.typeRadio,
  300. keyword: this.form.content,
  301. status: this.form.status
  302. };
  303. this.$refs[formName].validate(valid => {
  304. if (valid) {
  305. APILimits.changeRecognition(reqBody).then(res => {
  306. console.log(res);
  307. if (res.code === 0) {
  308. this.dialogPvVisible = false;
  309. this.$message({
  310. message: "修改成功",
  311. type: "success"
  312. });
  313. this.getList();
  314. }
  315. });
  316. } else {
  317. return false;
  318. }
  319. });
  320. },
  321. // 删除
  322. onDelete(row) {
  323. console.log("删除", row);
  324. this.$confirm("是否删除?", {
  325. confirmButtonText: "确定",
  326. cancelButtonText: "取消",
  327. type: "warning"
  328. })
  329. .then(() => {
  330. let reqBody = {
  331. id: row.id,
  332. type: "system"
  333. };
  334. APILimits.delRecognition(reqBody).
  335. then(res => {
  336. if ((res.code === 0)) {
  337. this.$message({
  338. type: "success",
  339. message: "删除成功!"
  340. });
  341. this.getList();
  342. } else {
  343. this.$message({
  344. type: "error",
  345. message: "删除失败!"
  346. });
  347. }
  348. });
  349. })
  350. .catch(() => {});
  351. },
  352. // 获取分页数据
  353. getList() {
  354. this.loading = true;
  355. let reqBody = {
  356. pageNumber: this.page,
  357. begNumber: this.limit,
  358. categoryId: this.model,
  359. keyword: this.searchValue
  360. };
  361. APILimits.getRecognition(reqBody).then(res => {
  362. this.list = res.data.map(m => {
  363. return {
  364. type: this.transfromToType(m.kindId),
  365. model: m.categoryName,
  366. content: m.keyword,
  367. createTime: m.createTime,
  368. kindId: m.kindId,
  369. categoryId: m.categoryId,
  370. status: m.status === true ? '打开' : '关闭',
  371. id: m.id
  372. };
  373. });
  374. this.total = res.count;
  375. });
  376. this.loading = false;
  377. },
  378. // 获取分类数据
  379. getAreaCategoryQuery() {
  380. let reqBody = {
  381. pageNumber: 1,
  382. begNumber: 20,
  383. keyword: ""
  384. };
  385. APILimits.areaCategoryQuery(reqBody).then(res => {
  386. this.formOptions = res.data.map(m => {
  387. return {
  388. value: m.categoryId,
  389. label:
  390. m.categoryName +
  391. "--" +
  392. `${this.transfromToType(m.kindId)}`
  393. };
  394. });
  395. this.modelOptions = this.formOptions;
  396. });
  397. },
  398. beforeUpload(file) {
  399. const isLt1M = file.size / 1024 / 1024 < 1;
  400. if (isLt1M) {
  401. return true;
  402. }
  403. this.$message({
  404. message: "导入的文件不能超过1m",
  405. type: "warning"
  406. });
  407. return false;
  408. },
  409. handleSuccess({ results, header }) {
  410. this.list = results;
  411. this.columns = header.map(h => {
  412. return { prop: h, title: h };
  413. });
  414. this.dialogUpload = false;
  415. },
  416. // 弹窗选择框值变化时
  417. onSelectChange(value) {
  418. this.form.categoryId = value;
  419. },
  420. // 页面选择框变化
  421. outSelecChange(value) {
  422. this.model = value;
  423. },
  424. // 点击清除按钮时
  425. onClear() {
  426. this.$refs["pages"].currentPage = 1;
  427. this.getList();
  428. }
  429. },
  430. mounted() {
  431. this.getList();
  432. this.getAreaCategoryQuery();
  433. }
  434. };
  435. </script>
  436. <style scoped>
  437. </style>