index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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="cameraName">
  5. <el-input
  6. v-model="queryParams.cameraName"
  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. icon="el-icon-plus"
  22. size="mini"
  23. @click="handleAdd"
  24. v-hasPermi="['zcustom:camera:add']"
  25. >新增</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button
  29. type="danger"
  30. icon="el-icon-delete"
  31. size="mini"
  32. :disabled="multiple"
  33. @click="handleDelete"
  34. v-hasPermi="['zcustom:camera:remove']"
  35. >删除</el-button>
  36. </el-col>
  37. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  38. </el-row>
  39. <el-table v-loading="loading" :data="cameraList" @selection-change="handleSelectionChange">
  40. <el-table-column type="selection" width="55" align="center" />
  41. <el-table-column label="序号" width="50">
  42. <template slot-scope="scope">
  43. {{(scope.$index + 1) + ((queryParams.pageNum - 1) * queryParams.pageSize)}}
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="摄像头名称" align="center" prop="cameraName" />
  47. <el-table-column label="摄像头编码" align="center" prop="cameraCode"/>
  48. <el-table-column label="创建时间" align="center" prop="createTime" />
  49. <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
  50. <template slot-scope="scope">
  51. <el-button
  52. size="mini"
  53. type="text"
  54. icon="el-icon-edit"
  55. @click="handleUpdate(scope.row)"
  56. v-hasPermi="['zcustom:camera:edit']"
  57. >修改</el-button>
  58. <el-button
  59. size="mini"
  60. type="text"
  61. icon="el-icon-delete"
  62. @click="handleDelete(scope.row)"
  63. v-hasPermi="['zcustom:camera:remove']"
  64. >删除</el-button>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. <pagination
  69. v-show="total>0"
  70. :total="total"
  71. :page.sync="queryParams.pageNum"
  72. :limit.sync="queryParams.pageSize"
  73. @pagination="getList"
  74. />
  75. <!-- 添加或修改摄像头对话框 -->
  76. <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="800px" append-to-body>
  77. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  78. <el-form-item label="摄像头名称" prop="cameraName">
  79. <el-input v-model="form.cameraName" placeholder="请输入摄像头名称" />
  80. </el-form-item>
  81. <el-form-item label="摄像头编码" prop="cameraCode">
  82. <el-input v-model="form.cameraCode" placeholder="请输入摄像头编码" />
  83. </el-form-item>
  84. <el-form-item label="所属项目" prop="projectId">
  85. <el-select v-model="form.projectId" placeholder="请选择">
  86. <el-option
  87. v-for="item in projectList"
  88. :key="item.id"
  89. :label="item.projectName"
  90. :value="item.id">
  91. </el-option>
  92. </el-select>
  93. </el-form-item>
  94. </el-form>
  95. <div slot="footer" class="dialog-footer">
  96. <el-button type="primary" @click="submitForm">确 定</el-button>
  97. <el-button @click="cancel">取 消</el-button>
  98. </div>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import { listCamera, getCamera, delCamera, addCamera, updateCamera } from "@/api/zcustom/camera";
  104. import { listProject } from '@/api/zcustom/project'
  105. export default {
  106. name: "Camera",
  107. data() {
  108. return {
  109. // 根路径
  110. baseURL: process.env.VUE_APP_BASE_API,
  111. // 遮罩层
  112. loading: true,
  113. // 选中数组
  114. ids: [],
  115. // 非单个禁用
  116. single: true,
  117. // 非多个禁用
  118. multiple: true,
  119. // 显示搜索条件
  120. showSearch: true,
  121. // 总条数
  122. total: 0,
  123. // 摄像头表格数据
  124. cameraList: [],
  125. projectList: [],
  126. // 弹出层标题
  127. title: "",
  128. // 是否显示弹出层
  129. open: false,
  130. // 查询参数
  131. queryParams: {
  132. pageNum: 1,
  133. pageSize: 10,
  134. cameraName: null,
  135. cameraCode: null,
  136. projectId: null,
  137. type: null,
  138. status: null,
  139. onlineFlag: null,
  140. connectFlag: null,
  141. },
  142. // 表单参数
  143. form: {},
  144. // 表单校验
  145. rules: {
  146. cameraName: [
  147. { required: true, message: "摄像头名称不能为空", trigger: "blur" }
  148. ],
  149. projectId: [
  150. { required: true, message: "所属项目id不能为空", trigger: "blur" }
  151. ],
  152. cameraCode: [
  153. { required: true, message: "在线标志不能为空", trigger: "blur" }
  154. ]
  155. }
  156. };
  157. },
  158. created() {
  159. this.getList();
  160. this.getPrjList()
  161. },
  162. methods: {
  163. /** 查询摄像头列表 */
  164. getList() {
  165. this.loading = true;
  166. listCamera(this.queryParams).then(response => {
  167. this.cameraList = response.data.records;
  168. this.total = response.data.total;
  169. this.loading = false;
  170. });
  171. },
  172. getPrjList() {
  173. listProject().then(response => {
  174. this.projectList = response.data.records;
  175. });
  176. },
  177. // 取消按钮
  178. cancel() {
  179. this.open = false;
  180. this.reset();
  181. },
  182. // 表单重置
  183. reset() {
  184. this.form = {
  185. id: null,
  186. cameraName: null,
  187. cameraCode: null,
  188. projectId: null,
  189. type: null,
  190. status: "0",
  191. onlineFlag: null,
  192. connectFlag: null,
  193. delFlag: null,
  194. };
  195. this.resetForm("form");
  196. },
  197. /** 搜索按钮操作 */
  198. handleQuery() {
  199. this.queryParams.pageNum = 1;
  200. this.getList();
  201. },
  202. /** 重置按钮操作 */
  203. resetQuery() {
  204. this.resetForm("queryForm");
  205. this.handleQuery();
  206. },
  207. // 多选框选中数据
  208. handleSelectionChange(selection) {
  209. this.ids = selection.map(item => item.id)
  210. this.single = selection.length!==1
  211. this.multiple = !selection.length
  212. },
  213. /** 新增按钮操作 */
  214. handleAdd() {
  215. this.reset();
  216. this.open = true;
  217. this.title = "添加摄像头";
  218. },
  219. /** 修改按钮操作 */
  220. handleUpdate(row) {
  221. this.reset();
  222. const id = row.id || this.ids
  223. getCamera(id).then(response => {
  224. this.form = response.data;
  225. this.open = true;
  226. this.title = "修改摄像头";
  227. });
  228. },
  229. /** 提交按钮 */
  230. submitForm() {
  231. this.$refs["form"].validate(valid => {
  232. if (valid) {
  233. if (this.form.id != null) {
  234. updateCamera(this.form).then(response => {
  235. this.$modal.msgSuccess("修改成功");
  236. this.open = false;
  237. this.getList();
  238. });
  239. } else {
  240. addCamera(this.form).then(response => {
  241. this.$modal.msgSuccess("新增成功");
  242. this.open = false;
  243. this.getList();
  244. });
  245. }
  246. }
  247. });
  248. },
  249. /** 删除按钮操作 */
  250. handleDelete(row) {
  251. const ids = row.id || this.ids;
  252. this.$modal.confirm('是否确认删除?').then(function() {
  253. return delCamera(ids);
  254. }).then(() => {
  255. this.getList();
  256. this.$modal.msgSuccess("删除成功");
  257. }).catch(() => {});
  258. },
  259. }
  260. };
  261. </script>