smartMachine.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <!--硬件管理/智能一体机-->
  2. <template>
  3. <div class="smartMachine">
  4. <!--<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" class="form-box">-->
  5. <!--<el-form-item label="学院" prop="deptId">-->
  6. <!--<el-select v-model="queryParams.deptId" placeholder="请选择学院" clearable @change="handleNodeClick">-->
  7. <!--<el-option-->
  8. <!--v-for="dict in deptOptions"-->
  9. <!--:key="dict.deptId"-->
  10. <!--:label="dict.deptName"-->
  11. <!--:value="dict.deptId"-->
  12. <!--&gt;</el-option>-->
  13. <!--</el-select>-->
  14. <!--</el-form-item>-->
  15. <!--&lt;!&ndash;<el-form-item label="学院" prop="type">&ndash;&gt;-->
  16. <!--&lt;!&ndash;<el-select v-model="queryParams.name" placeholder="请选择学院" clearable size="small">&ndash;&gt;-->
  17. <!--&lt;!&ndash;<el-option label="请选择字典生成" value="" />&ndash;&gt;-->
  18. <!--&lt;!&ndash;</el-select>&ndash;&gt;-->
  19. <!--&lt;!&ndash;</el-form-item>&ndash;&gt;-->
  20. <!--<el-form-item label="实验室" prop="subjectId">-->
  21. <!--<el-select v-model="queryParams.subjectId" clearable placeholder="请选择实验室">-->
  22. <!--<el-option-->
  23. <!--v-for="item in subjectOptions"-->
  24. <!--:key="item.id"-->
  25. <!--:label="item.name"-->
  26. <!--:value="item.id">-->
  27. <!--</el-option>-->
  28. <!--</el-select>-->
  29. <!--</el-form-item>-->
  30. <!--&lt;!&ndash;<el-form-item label="实验室" prop="type">&ndash;&gt;-->
  31. <!--&lt;!&ndash;<el-select v-model="queryParams.factory" placeholder="请选择实验室" clearable size="small">&ndash;&gt;-->
  32. <!--&lt;!&ndash;<el-option label="请选择字典生成" value="" />&ndash;&gt;-->
  33. <!--&lt;!&ndash;</el-select>&ndash;&gt;-->
  34. <!--&lt;!&ndash;</el-form-item>&ndash;&gt;-->
  35. <!--<el-form-item label="状态" prop="operate">-->
  36. <!--<el-select v-model="queryParams.operate" placeholder="请选择状态" clearable size="small">-->
  37. <!--<el-option label="在线" value="ONLINE" />-->
  38. <!--<el-option label="离线" value="OFFLINE" />-->
  39. <!--<el-option label="开启" value="OPEN" />-->
  40. <!--<el-option label="关闭" value="CLOSE" />-->
  41. <!--</el-select>-->
  42. <!--</el-form-item>-->
  43. <!--<el-form-item style="float: right;">-->
  44. <!--<el-col :span="1.5">-->
  45. <!--<p class="add-button-one-120"-->
  46. <!--@click="handleAdd"-->
  47. <!--v-hasPermi="['laboratory:hardware:add']"-->
  48. <!--&gt;<i class="el-icon-plus"></i>新增硬件</p>-->
  49. <!--</el-col>-->
  50. <!--</el-form-item>-->
  51. <!--<el-form-item>-->
  52. <!--<p class="inquire-button-one" @click="handleQuery">查询</p>-->
  53. <!--<p class="reset-button-one" @click="resetQuery">重置</p>-->
  54. <!--</el-form-item>-->
  55. <!--</el-form>-->
  56. <el-table v-loading="loading" border :data="hardwareList" @selection-change="handleSelectionChange">
  57. <el-table-column label="名称" align="left" prop="name" />
  58. <el-table-column label="学院" align="left" prop="deptName" />
  59. <el-table-column label="实验室" align="left" prop="subjectName" />
  60. <el-table-column label="设备编号" align="left" prop="hardwareNum" />
  61. <el-table-column label="状态" align="left" >
  62. <template slot-scope="scope">
  63. <p :class="scope.row.status==0?'table-type-color-ash':(scope.row.status==2?'table-type-color-green':(!scope.row.status?'table-type-color-red':''))">{{scope.row.status==0?'离线':(scope.row.status==2?'在线':(!scope.row.status?'离线':''))}}</p>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120" v-if="tableButtonType">
  67. <template slot-scope="scope">
  68. <div class="button-box">
  69. <el-dropdown @command="moreClick">
  70. <p class="table-min-button">更多>></p>
  71. <el-dropdown-menu slot="dropdown">
  72. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;" :command="{row:scope.row,command:1}"
  73. v-hasPermiAnd="['laboratory:hardware:query','laboratory:hardware:edit']">修改设备</el-dropdown-item>
  74. <el-dropdown-item style="margin:0 10px;" :command="{row:scope.row,command:2}"
  75. v-hasPermi="['laboratory:hardware:remove']">删除设备</el-dropdown-item>
  76. </el-dropdown-menu>
  77. </el-dropdown>
  78. </div>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <pagination :page-sizes="[20, 30, 40, 50]"
  83. v-show="total>0"
  84. :total="total"
  85. layout="total, prev, pager, next, sizes, jumper"
  86. :page.sync="queryParams.pageNum"
  87. :limit.sync="queryParams.pageSize"
  88. @pagination="getList"
  89. />
  90. <!-- 添加或修改硬件对话框 -->
  91. <el-drawer
  92. class="videoSurveillance-drawer"
  93. :visible.sync="drawer"
  94. direction="rtl"
  95. ref="drawer"
  96. :with-header="false"
  97. :show-close="false"
  98. :before-close="handleClose">
  99. <div class="videoSurveillance-drawer-max-box">
  100. <div class="videoSurveillance-drawer-content">
  101. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  102. <el-form-item label="硬件名称" prop="name">
  103. <el-input
  104. v-model="form.name"
  105. placeholder="请输入硬件名称"
  106. clearable
  107. size="small"
  108. maxLength="8"
  109. />
  110. </el-form-item>
  111. <el-form-item label="硬件类型" v-if="pageType==''" prop="type">
  112. <el-select v-model="form.type" placeholder="请选择硬件类型">
  113. <el-option label="请选择硬件类型" value="" />
  114. <el-option v-for="hardType in hardTypeOptions"
  115. :key="hardType.enumName"
  116. :label="hardType.name"
  117. :value="hardType.enumName">
  118. </el-option>
  119. </el-select>
  120. </el-form-item>
  121. <el-form-item label="设备编号" prop="hardwareNum">
  122. <el-input
  123. v-model="form.hardwareNum"
  124. placeholder="请输入设备编号"
  125. clearable
  126. size="small"
  127. maxlength="20"
  128. />
  129. </el-form-item>
  130. <el-form-item label="实验室" prop="subjectId">
  131. <el-select v-model="form.subjectId" placeholder="请选择实验室">
  132. <el-option v-for="lab in labListOptions"
  133. :key="lab.id"
  134. :label="lab.name"
  135. :value="lab.id">
  136. </el-option>
  137. </el-select>
  138. </el-form-item>
  139. <!--<el-form-item label="硬件位置" prop="position">-->
  140. <!--<div class="map-box" :style="'width:'+mapData.widthData*3+'px;height:'+mapData.heightData*3+'px;'">-->
  141. <!--<div v-for="(item,index1) in mapData.list" v-if="isUpdate"-->
  142. <!--:style="'top:'+item.y*3+'px;left:'+item.x*3+'px;'"-->
  143. <!--@mouseenter="moveClick(index1)"-->
  144. <!--@mousedown="move">-->
  145. <!--{{form.name?form.name:'未命名'}}-->
  146. <!--</div>-->
  147. <!--<p class="map-p" v-for="(item) in mapList" :style="'top:'+item.y*3+'px;left:'+item.x*3+'px;'">{{item.name}}</p>-->
  148. <!--</div>-->
  149. <!--</el-form-item>-->
  150. </el-form>
  151. </div>
  152. <div class="videoSurveillance-bottom-button-box">
  153. <p></p>
  154. <p @click="offDrawer">取消</p>
  155. <p @click="submitForm">提交</p>
  156. </div>
  157. </div>
  158. </el-drawer>
  159. </div>
  160. </template>
  161. <script>
  162. import { subjectDictList } from "@/api/laboratory/group";
  163. import { listDepartments } from "@/api/system/dept";
  164. import { listHardware, getHardware, delHardware, addHardware, updateHardware,queryHardwareType,getHardwareDetail,getSubjectLayout } from "@/api/laboratory/hardware";
  165. import { treeselect } from "@/api/system/dept";
  166. import Treeselect from "@riophae/vue-treeselect";
  167. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  168. import { listRelay } from "@/api/laboratory/relay";
  169. export default {
  170. props:{
  171. pageType:{},
  172. queryParams:{}
  173. },
  174. components: { Treeselect },
  175. name: "smartMachine",
  176. data() {
  177. return {
  178. tableButtonType:this.hasPermiDom(['laboratory:hardware:query','laboratory:hardware:edit','laboratory:hardware:remove']),
  179. index:'',
  180. // 遮罩层
  181. loading: true,
  182. // 选中数组
  183. ids: [],
  184. // 非单个禁用
  185. single: true,
  186. // 非多个禁用
  187. multiple: true,
  188. // 显示搜索条件
  189. showSearch: true,
  190. // 总条数
  191. total: 0,
  192. // 硬件表格数据
  193. hardwareList: [],
  194. // 弹出层标题
  195. title: "",
  196. // 是否显示弹出层
  197. open: false,
  198. // 部门树选项
  199. deptOptions: [],
  200. subjectOptions: undefined,
  201. isUpdate:false,
  202. // 查询参数
  203. // queryParams: {
  204. // pageNum: 1,
  205. // pageSize:20,
  206. // name: null,
  207. // factory: null,
  208. // type: null,
  209. // hardwareNum: null,
  210. // subjectId: null,
  211. // deptId: null,
  212. // deptName: null,
  213. // operate: null,
  214. // userId: null,
  215. // },
  216. // 表单参数
  217. form: {},
  218. // 表单校验
  219. rules: {
  220. name: [
  221. { required: true, message: "请输入硬件名称", trigger: "blur" },
  222. { required: true, message: "请输入硬件名称", validator: this.spaceJudgment, trigger: "blur" }
  223. ],
  224. type: [
  225. { required: true, message: "请选择硬件类型", trigger: "blur" }
  226. ],
  227. hardwareNum: [
  228. { required: true, message: "请输入设备编号", trigger: "blur" },
  229. { required: true, message: "请输入设备编号", validator: this.spaceJudgment, trigger: "blur" }
  230. ],
  231. subjectId:[
  232. { required: true, message: "请选择实验室", trigger: "blur" },
  233. ]
  234. },
  235. hardTypeOptions:{},
  236. labListOptions:{},
  237. // 关联实验室弹窗开关
  238. drawer:false,
  239. mapData:{
  240. widthData:"60",
  241. heightData:"123",
  242. list:[
  243. {
  244. id: "",
  245. top:0,
  246. left:0
  247. }
  248. ]
  249. },
  250. mapList:[],
  251. };
  252. },
  253. created() {
  254. this.getList();
  255. this.getDeptList();
  256. },
  257. methods: {
  258. //删除
  259. delBox(item){
  260. console.log(item)
  261. },
  262. moveClick(index){
  263. this.moveIndex = index
  264. console.log(",index",index)
  265. },
  266. //锚点拖动
  267. move(e){
  268. let odiv = e.target; //获取目标元素
  269. //算出鼠标相对元素的位置
  270. let disX = e.clientX - odiv.offsetLeft;
  271. let disY = e.clientY - odiv.offsetTop;
  272. document.onmousemove = (e)=>{ //鼠标按下并移动的事件
  273. //用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
  274. let left = e.clientX - disX;
  275. let top = e.clientY - disY;
  276. //绑定元素位置到positionX和positionY上面
  277. //移动当前元素
  278. if(left>0&&left<(this.mapData.widthData*3-60)){
  279. odiv.style.left = left + 'px';
  280. this.mapData.list[this.moveIndex].left = left;
  281. this.mapData.list[this.moveIndex].minLeft = parseInt(left/6);
  282. }
  283. if(top>0&&top<(this.mapData.heightData*3-60)){
  284. odiv.style.top = top + 'px';
  285. this.mapData.list[this.moveIndex].top = top;
  286. this.mapData.list[this.moveIndex].minTop = parseInt(top/6);
  287. }
  288. };
  289. document.onmouseup = (e) => {
  290. document.onmousemove = null;
  291. document.onmouseup = null;
  292. };
  293. },
  294. getHardTypeList(){
  295. queryHardwareType().then(response => {
  296. if(response.code==200){
  297. this.hardTypeOptions=response.data;
  298. }
  299. console.log(this.hardTypeOptions)
  300. });
  301. },
  302. //关联实验室弹窗
  303. drawerBoxOnTwo(){
  304. this.drawerTwo = true;
  305. },
  306. //关联实验室弹窗
  307. drawerBoxOn(){
  308. this.drawer = true;
  309. },
  310. //关闭弹窗
  311. offDrawer(){
  312. this.$refs.drawer.closeDrawer();
  313. },
  314. //弹窗关闭前回调
  315. handleClose(done) {
  316. this.$confirm('确认关闭吗?')
  317. .then(_ => {
  318. done();
  319. })
  320. .catch(_ => {});
  321. },
  322. //更多选项
  323. moreClick(item){
  324. if(item.command == 1){
  325. this.handleUpdate(item.row)
  326. }else if(item.command == 2){
  327. this.handleDelete(item.row)
  328. }
  329. },
  330. /** 查询硬件列表 */
  331. getList() {
  332. this.loading = true;
  333. this.queryParams.type = this.pageType;
  334. listHardware(this.queryParams).then(response => {
  335. this.hardwareList = response.rows;
  336. this.total = response.total;
  337. this.loading = false;
  338. });
  339. },
  340. // 取消按钮
  341. cancel() {
  342. this.open = false;
  343. this.reset();
  344. },
  345. loadHardware(){
  346. let self = this;
  347. this.mapList = [];
  348. let newId = this.mapData.list[0].id;
  349. // this.mapData.list = [];
  350. let queryParam = {};
  351. if(this.form.id){
  352. queryParam.id = this.form.id;
  353. }else{
  354. queryParam.id = -1;
  355. }
  356. queryParam.subjectId = this.form.subjectId;
  357. getHardwareDetail(queryParam).then(response => {
  358. let subHardList = response.data.subjectHardPosiList;
  359. for(var i=0;i<subHardList.length;i++){
  360. if(response.data.subjectHardPosiList[i].id!=newId){
  361. this.mapList.push({"name":response.data.subjectHardPosiList[i].hardName,"y":(response.data.subjectHardPosiList[i].horizontalAxis/3).toFixed(0),"x":(response.data.subjectHardPosiList[i].verticalAxis/3).toFixed(0)});
  362. }
  363. }
  364. this.$forceUpdate();
  365. });
  366. getSubjectLayout(this.form.subjectId).then(response => {
  367. if(response.data){
  368. this.mapData.widthData = response.data.layWidth;
  369. this.mapData.heightData = response.data.layHeight;
  370. }else{
  371. this.mapData.widthData = 60;
  372. this.mapData.heightData = 123;
  373. }
  374. this.$forceUpdate();
  375. });
  376. let obj = JSON.parse(JSON.stringify(this.mapData.list[0]));
  377. obj.x = 0;
  378. obj.y = 0;
  379. obj.top = 0;
  380. obj.left = 0;
  381. this.mapData.list.splice(0,1);
  382. setTimeout(function(){
  383. self.mapData.list.push(obj);
  384. },50);
  385. this.$forceUpdate()
  386. },
  387. /** 查询实验室字典列表 */
  388. getSubjectDictList (deptId) {
  389. this.subjectOptions = null;
  390. this.loading = true;
  391. // this.queryParams.deptId = deptId;
  392. let params = {};
  393. params.deptId = deptId;
  394. this.queryParams.subjectId = "";
  395. subjectDictList(params).then(response => {
  396. this.subjectOptions = response.data;
  397. this.loading = false;
  398. });
  399. },
  400. /** 查询学院列表 */
  401. getDeptList() {
  402. listDepartments().then(response => {
  403. this.$set(this, 'deptOptions', response.data)
  404. });
  405. },
  406. // 筛选节点
  407. filterNode(value, data) {
  408. if (!value) return true;
  409. return data.label.indexOf(value) !== -1;
  410. },
  411. // 节点单击事件
  412. handleNodeClick(data) {
  413. this.queryParams.deptId = data;
  414. // console.log("data",data);
  415. this.getSubjectDictList(data);
  416. // this.getList();
  417. },
  418. // 表单重置
  419. reset() {
  420. this.form = {
  421. id: null,
  422. name: null,
  423. factory: null,
  424. type: null,
  425. hardwareNum: null,
  426. subjectId: null,
  427. deptId: null,
  428. deptName: null,
  429. operate: 0,
  430. createTime: null,
  431. userId: null,
  432. createBy: null,
  433. updateTime: null,
  434. updateBy: null,
  435. remark: null
  436. };
  437. this.resetForm("form");
  438. },
  439. getLabList(){
  440. subjectDictList().then(response => {
  441. console.log(response)
  442. if(response.code==200){
  443. this.labListOptions=response.data;
  444. }
  445. console.log(this.labListOptions)
  446. });
  447. },
  448. /** 搜索按钮操作 */
  449. handleQuery() {
  450. this.queryParams.pageNum = 1;
  451. this.getList();
  452. },
  453. /** 重置按钮操作 */
  454. resetQuery() {
  455. this.resetForm("queryForm");
  456. this.handleQuery();
  457. },
  458. // 多选框选中数据
  459. handleSelectionChange(selection) {
  460. this.ids = selection.map(item => item.id)
  461. this.single = selection.length!==1
  462. this.multiple = !selection.length
  463. },
  464. /** 新增按钮操作 */
  465. handleAdd() {
  466. this.reset();
  467. this.mapList = []
  468. this.mapData.list = [{
  469. id: "",
  470. top:0,
  471. left:0
  472. }];
  473. this.isUpdate=true;
  474. this.form.type=this.pageType;
  475. this.drawer = true;
  476. this.title = "添加硬件";
  477. this.getHardTypeList();
  478. this.getLabList();
  479. // this.reset();
  480. // this.open = true;
  481. // this.title = "添加硬件";
  482. // this.getLabList();
  483. // this.form.type=this.pageType;
  484. },
  485. /** 修改按钮操作 */
  486. handleUpdate(row) {
  487. this.reset();
  488. this.mapList = [];
  489. this.mapData.list = [];
  490. this.isUpdate=true;
  491. this.form.type=this.pageType;
  492. this.getHardTypeList();
  493. this.getLabList();
  494. const id = row.id || this.ids
  495. let queryParam = {};
  496. queryParam.id = id;
  497. queryParam.subjectId = row.subjectId;
  498. getHardwareDetail(queryParam).then(response => {
  499. this.form = response.data;
  500. this.$forceUpdate;
  501. this.title = "修改硬件";
  502. this.drawer = true;
  503. });
  504. },
  505. /** 提交按钮 */
  506. submitForm() {
  507. this.form.hardwarePosition={
  508. horizontalAxis:'',
  509. verticalAxis:''
  510. }
  511. this.form.type=this.pageType;
  512. // this.form.hardwarePosition.horizontalAxis=this.mapData.list[0].top;
  513. // this.form.hardwarePosition.verticalAxis=this.mapData.list[0].left;
  514. this.$refs["form"].validate(valid => {
  515. if (valid) {
  516. if (this.form.id != null) {
  517. updateHardware(this.form).then(response => {
  518. this.msgSuccess("修改成功");
  519. this.drawer = false;
  520. this.getList();
  521. });
  522. } else {
  523. addHardware(this.form).then(response => {
  524. this.msgSuccess("新增成功");
  525. this.drawer = false;
  526. this.getList();
  527. });
  528. }
  529. }
  530. });
  531. // this.$refs["form"].validate(valid => {
  532. // if (valid) {
  533. // if (this.form.id != null) {
  534. // updateHardware(this.form).then(response => {
  535. // this.msgSuccess("修改成功");
  536. // this.open = false;
  537. // this.getList();
  538. // });
  539. // } else {
  540. // addHardware(this.form).then(response => {
  541. // this.msgSuccess("新增成功");
  542. // this.open = false;
  543. // this.getList();
  544. // });
  545. // }
  546. // }
  547. // });
  548. },
  549. /** 删除按钮操作 */
  550. handleDelete(row) {
  551. const ids = row.id || this.ids;
  552. this.$confirm('是否确认删除硬件?', "警告", {
  553. confirmButtonText: "确定",
  554. cancelButtonText: "取消",
  555. type: "warning"
  556. }).then(function() {
  557. return delHardware(ids);
  558. }).then(() => {
  559. this.getList();
  560. this.msgSuccess("删除成功");
  561. }).catch(() => {});
  562. },
  563. /** 导出按钮操作 */
  564. handleExport() {
  565. this.download('laboratory/hardware/export', {
  566. ...this.queryParams
  567. }, `laboratory_hardware.xlsx`)
  568. }
  569. }
  570. };
  571. </script>
  572. <style scoped lang="scss">
  573. .smartMachine{
  574. flex: 1;
  575. display: flex!important;
  576. flex-direction: column;
  577. padding:20px!important;
  578. overflow: hidden;
  579. .form-box{
  580. }
  581. .button-box{
  582. width:350px;
  583. display: flex;
  584. }
  585. }
  586. </style>