smartMachine.vue 21 KB

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