天波用户运营管理后台系统
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

443 lines
15KB

  1. <!--
  2. * @Date: 2021-11-30 09:44:24
  3. * @LastEditors: JinxuChen
  4. * @LastEditTime: 2021-12-08 15:16:20
  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. >
  37. <el-option
  38. v-for="item in modelOptions"
  39. :key="item.value"
  40. :label="item.label"
  41. :value="item.value"
  42. class="filter-item"
  43. ></el-option>
  44. </el-select>
  45. <!-- 搜索 -->
  46. <el-input
  47. v-model="searchValue"
  48. placeholder="请输入关键字"
  49. style="width: 200px; margin-left: 10px;"
  50. class="filter-item"
  51. @keyup.enter.native="onSearch"
  52. clearable
  53. />
  54. <el-button
  55. class="filter-item"
  56. style="margin-left: 10px;"
  57. type="primary"
  58. icon="el-icon-search"
  59. @click="onSearch"
  60. >搜索</el-button>
  61. </div>
  62. <TTable :tableData="list" :columns="columns" @update="onUpdate" @delete="onDelete"></TTable>
  63. <!-- 分页 -->
  64. <pagination
  65. v-show="total>0"
  66. :total="total"
  67. :page.sync="page"
  68. ref="pages"
  69. :limit.sync="limit"
  70. @pagination="getList"
  71. />
  72. <el-dialog :visible.sync="dialogPvVisible" :title="dialogTitle">
  73. <el-form
  74. ref="form"
  75. :rules="formRules"
  76. :model="form"
  77. label-position="left"
  78. label-width="70px"
  79. style="width: 400px;"
  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: 80%"/>
  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 TopMenu from "@/components/TopMenu";
  128. import TTable from "../../../components/TTable/TTable";
  129. import Pagination from "@/components/Pagination";
  130. import UploadExcelComponent from "@/components/UploadExcel/index.vue";
  131. import APILimits from "@/api/off-limits-manage";
  132. export default {
  133. name: "",
  134. components: { TTable, TopMenu, Pagination, UploadExcelComponent },
  135. data() {
  136. return {
  137. buttonList: [
  138. {
  139. name: "添加",
  140. type: "success",
  141. click: () => {
  142. this.onAdd();
  143. }
  144. },
  145. {
  146. name: "批量导入",
  147. type: "success",
  148. click: () => {
  149. this.onImportBatch();
  150. }
  151. }
  152. ],
  153. type: "",
  154. model: "",
  155. modelOptions: [],
  156. searchValue: "",
  157. columns: [
  158. { prop: "type", title: "类型" },
  159. { prop: "model", title: "类别" },
  160. { prop: "content", title: "内容名称" },
  161. { prop: "createTime", title: "创建时间" },
  162. { prop: "status", title: "状态" },
  163. {
  164. action: true,
  165. title: "操作",
  166. actions: [
  167. { fnName: "update", title: "修改", type: "primary" },
  168. { fnName: "delete", title: "删除", type: "error" }
  169. ]
  170. }
  171. ],
  172. list: [],
  173. total: 0,
  174. page: 1,
  175. limit: 10,
  176. dialogPvVisible: false,
  177. dialogStatus: "",
  178. dialogTitle: "修改告警识别内容",
  179. form: {
  180. typeRadio: 1,
  181. model: "",
  182. content: "",
  183. createTime: "",
  184. resource: "",
  185. categoryId: "",
  186. status: true,
  187. id: ""
  188. },
  189. formRules: {
  190. content: [
  191. {
  192. required: true,
  193. message: "请输入内容名称",
  194. trigger: "blur"
  195. }
  196. ],
  197. typeRadio: [
  198. { required: true, message: "请选择类型", trigger: "change" }
  199. ],
  200. model: [
  201. { required: true, message: "请选择类别", trigger: "change" }
  202. ]
  203. },
  204. formOptions: [],
  205. dialogUpload: false,
  206. loading: false
  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 = Object.assign({}, row); */ ;
  288. this.form.categoryId = row.categoryId;
  289. this.form.createTime = new Date(this.form.createTime);
  290. this.form.typeRadio = row.kindId;
  291. this.form.model = row.categoryId;
  292. this.form.id = row.id;
  293. this.form.content = row.content;
  294. this.form.status = row.status === '打开' ? true : false;
  295. },
  296. update(formName) {
  297. let reqBody = {
  298. id: this.form.id, //0 是新增 选中的rouw的id是修改
  299. categoryId: this.form.categoryId,
  300. kindId: this.form.typeRadio,
  301. keyword: this.form.content,
  302. status: this.form.status
  303. };
  304. this.$refs[formName].validate(valid => {
  305. if (valid) {
  306. APILimits.changeRecognition(reqBody).then(res => {
  307. console.log(res);
  308. if (res.code === 0) {
  309. this.dialogPvVisible = false;
  310. this.$message({
  311. message: "修改成功",
  312. type: "success"
  313. });
  314. this.getList();
  315. }
  316. });
  317. } else {
  318. return false;
  319. }
  320. });
  321. },
  322. // 删除
  323. onDelete(row) {
  324. console.log("删除", row);
  325. this.$confirm("是否删除?", {
  326. confirmButtonText: "确定",
  327. cancelButtonText: "取消",
  328. type: "warning"
  329. })
  330. .then(() => {
  331. let reqBody = {
  332. id: row.id,
  333. type: "system"
  334. };
  335. APILimits.delRecognition(reqBody).
  336. then(res => {
  337. if ((res.code === 0)) {
  338. this.$message({
  339. type: "success",
  340. message: "删除成功!"
  341. });
  342. this.getList();
  343. } else {
  344. this.$message({
  345. type: "error",
  346. message: "删除失败!"
  347. });
  348. }
  349. });
  350. })
  351. .catch(() => {});
  352. },
  353. // 获取分页数据
  354. getList() {
  355. this.loading = true;
  356. let reqBody = {
  357. pageNumber: this.page,
  358. begNumber: this.limit,
  359. categoryId: this.model,
  360. keyword: this.searchValue
  361. };
  362. APILimits.getRecognition(reqBody).then(res => {
  363. this.list = res.data.map(m => {
  364. return {
  365. type: this.transfromToType(m.kindId),
  366. model: m.categoryName,
  367. content: m.keyword,
  368. createTime: m.createTime,
  369. kindId: m.kindId,
  370. categoryId: m.categoryId,
  371. status: m.status === true ? '打开' : '关闭',
  372. id: m.id
  373. };
  374. });
  375. this.total = res.count;
  376. });
  377. this.loading = false;
  378. },
  379. // 获取分类数据
  380. getAreaCategoryQuery() {
  381. let reqBody = {
  382. pageNumber: 1,
  383. begNumber: 20,
  384. keyword: ""
  385. };
  386. APILimits.areaCategoryQuery(reqBody).then(res => {
  387. this.formOptions = res.data.map(m => {
  388. return {
  389. value: m.categoryId,
  390. label:
  391. m.categoryName +
  392. "--" +
  393. `${this.transfromToType(m.kindId)}`
  394. };
  395. });
  396. this.modelOptions = this.formOptions;
  397. });
  398. },
  399. beforeUpload(file) {
  400. const isLt1M = file.size / 1024 / 1024 < 1;
  401. if (isLt1M) {
  402. return true;
  403. }
  404. this.$message({
  405. message: "导入的文件不能超过1m",
  406. type: "warning"
  407. });
  408. return false;
  409. },
  410. handleSuccess({ results, header }) {
  411. this.list = results;
  412. this.columns = header.map(h => {
  413. return { prop: h, title: h };
  414. });
  415. this.dialogUpload = false;
  416. },
  417. // 弹窗选择框值变化时
  418. onSelectChange(value) {
  419. this.form.categoryId = value;
  420. },
  421. // 页面选择框变化
  422. outSelecChange(value) {
  423. this.model = value;
  424. },
  425. // 点击清除按钮时
  426. onClear() {
  427. this.$refs["pages"].currentPage = 1;
  428. this.getList();
  429. }
  430. },
  431. mounted() {
  432. this.getList();
  433. this.getAreaCategoryQuery();
  434. }
  435. };
  436. </script>
  437. <style scoped>
  438. </style>