index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <!-- 硬件分类 -->
  2. <template>
  3. <div class="app-container hardwareClassification">
  4. <div class="page-container hardwareClassificationPage" v-if="pageType === 1">
  5. <div class="page-form-title-box">
  6. <el-form :model="queryParams" class="form-box" ref="queryForm"
  7. :inline="true" style="width:100%;">
  8. <el-form-item label="" prop="searchValue">
  9. <el-input
  10. maxLength="30"
  11. v-model="queryParams.searchValue"
  12. placeholder="请输入名称/标识"
  13. style="width: 200px"
  14. />
  15. </el-form-item>
  16. <el-form-item label="" prop="state">
  17. <el-select v-model="queryParams.state" placeholder="请选择状态" style="width: 200px">
  18. <el-option
  19. v-for="dict in optionList"
  20. :key="dict.value"
  21. :label="dict.label"
  22. :value="dict.value"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
  27. <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
  28. <p class="page-add-common-style-button"
  29. style="float: right;"
  30. @click="dialogFormReset"
  31. v-hasPermiRouter="['iot:hardwareType:add']"
  32. >新增</p>
  33. </el-form>
  34. </div>
  35. <div class="page-content-box">
  36. <el-table class="table-box" v-loading="loading" border :data="dataList">
  37. <el-table-column label="名称" prop="hardwareTypeName" show-overflow-tooltip/>
  38. <el-table-column label="硬件标识" prop="hardwareTypeKey" width="200" show-overflow-tooltip/>
  39. <el-table-column label="物联分类" prop="deviceTypeName" width="200" show-overflow-tooltip/>
  40. <el-table-column label="物联标识" prop="deviceTypeKey" width="200" show-overflow-tooltip/>
  41. <el-table-column label="状态" prop="state" width="100" show-overflow-tooltip
  42. v-hasPermiRouter="['iot:hardwareType:edit']">
  43. <template slot-scope="scope">
  44. <el-switch
  45. @click.native="tableButton(5,scope.row)"
  46. class="switch captcha-img"
  47. :active-value="true"
  48. :inactive-value="false"
  49. active-color="#0183FA"
  50. inactive-color="#999"
  51. v-model="scope.row.state"
  52. active-text="启用"
  53. inactive-text="停用"
  54. disabled
  55. ></el-switch>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="创建时间" prop="createTime" width="200" show-overflow-tooltip>
  59. <template slot-scope="scope">
  60. <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
  64. <template slot-scope="scope">
  65. <div class="table-button-box">
  66. <p class="table-button-null"></p>
  67. <p class="table-button-p"
  68. @click="tableButton(2,scope.row)"
  69. v-hasPermiRouter="['iot:hardwareType:detail']"
  70. >详情</p>
  71. <p class="table-button-p"
  72. @click="tableButton(3,scope.row)"
  73. v-hasPermiRouter="['iot:hardwareType:edit']"
  74. >编辑</p>
  75. <p class="table-button-p"
  76. @click="tableButton(4,scope.row)"
  77. v-hasPermiRouter="['iot:hardwareType:del']"
  78. >删除</p>
  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. :page.sync="queryParams.page"
  88. :limit.sync="queryParams.pageSize"
  89. @pagination="getList"
  90. />
  91. </div>
  92. </div>
  93. <infoPage v-if="pageType == 2" :propsData="propsData"></infoPage>
  94. <!--新增弹窗-->
  95. <el-dialog class="iotClassification-dialog" :title='dialogTitle' width="540px" append-to-body
  96. :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
  97. :close-on-click-modal="false" :close-on-press-escape="false">
  98. <el-form :model="dialogForm" ref="dialogForm" :inline="true"
  99. :rules="dialogRules" class="addCheckPage-min" label-width="120px">
  100. <!--<el-form-item label="名称" prop="hardwareTypeName">-->
  101. <!--<el-input v-model="dialogForm.hardwareTypeName" disabled-->
  102. <!--placeholder="请输入名称" maxLength="10" style="width:320px;"/>-->
  103. <!--</el-form-item>-->
  104. <el-form-item label="硬件标识" prop="hardwareTypeKey">
  105. <el-select v-model="dialogForm.hardwareTypeKey" @change="hardwareChange" placeholder="请选择硬件标识" style="width: 320px">
  106. <el-option
  107. v-for="dict in keyOptionList"
  108. :key="dict.code"
  109. :label="dict.name"
  110. :value="dict.code"
  111. />
  112. </el-select>
  113. </el-form-item>
  114. <el-form-item label="状态" prop="state">
  115. <el-radio-group v-model="dialogForm.state">
  116. <el-radio :label="true" style="margin-left:20px;">启用</el-radio>
  117. <el-radio :label="false">禁用</el-radio>
  118. </el-radio-group>
  119. </el-form-item>
  120. <el-form-item label="物联标识" prop="deviceTypeKey">
  121. <el-select v-model="dialogForm.deviceTypeKey" clearable @change="deviceChange" placeholder="请选择物联标识" style="width: 320px">
  122. <el-option
  123. v-for="dict in iotTypeOptions"
  124. :key="dict.typeKey"
  125. :label="dict.typeName"
  126. :value="dict.typeKey"
  127. />
  128. </el-select>
  129. </el-form-item>
  130. <el-form-item label="小图标:" prop="icon">
  131. <el-upload
  132. style="width:100px;"
  133. class="iotClassification-dialog-upload"
  134. :action="uploadImgUrl"
  135. :show-file-list="false"
  136. :on-success="(res)=>handleAvatarSuccess(res,'icon')"
  137. :headers="headers"
  138. :before-upload="(file)=>beforeAvatarUpload(file)">
  139. <div class="center-img" style="margin-left:20px;">
  140. <img v-if="dialogForm.icon" :src="dialogForm.icon" style="max-width:40px;max-height:40px;">
  141. <p v-if="!dialogForm.icon" class="el-icon-upload" style="text-align: center;line-height:40px;font-size:30px;color:#0183FA;"></p>
  142. </div>
  143. </el-upload>
  144. </el-form-item>
  145. <el-form-item label="大图标:" prop="exceptionIcon">
  146. <el-upload
  147. style="width:100px;"
  148. class="iotClassification-dialog-upload"
  149. :action="uploadImgUrl"
  150. :show-file-list="false"
  151. :on-success="(res)=>handleAvatarSuccess(res,'exceptionIcon')"
  152. :headers="headers"
  153. :before-upload="(file)=>beforeAvatarUpload(file)">
  154. <div class="center-img" style="margin-left:20px;">
  155. <img v-if="dialogForm.exceptionIcon" :src="dialogForm.exceptionIcon" style="max-width:40px;max-height:40px;">
  156. <p v-if="!dialogForm.exceptionIcon" class="el-icon-upload" style="text-align: center;line-height:40px;font-size:30px;color:#E65D6E;"></p>
  157. </div>
  158. </el-upload>
  159. </el-form-item>
  160. </el-form>
  161. <div slot="footer" class="dialog-footer dialog-footer-box">
  162. <p class="dialog-footer-button-null"></p>
  163. <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
  164. <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
  165. <p class="dialog-footer-button-null"></p>
  166. </div>
  167. </el-dialog>
  168. <!--<add-page :propsData="propsData" v-if="pageType === 2"></add-page>-->
  169. </div>
  170. </template>
  171. <script>
  172. import { getToken } from "@/utils/auth";
  173. import {
  174. iotHardwareTypeAdd,
  175. iotHardwareTypeUpdate,
  176. iotHardwareTypeList,
  177. iotHardwareTypeDelete,
  178. iotHardwareTypeGetTypeKey,
  179. iotTypeGetAllTypes
  180. } from '@/api/iotDevice/index'
  181. import infoPage from "./infoPage.vue"
  182. export default {
  183. name: 'index',
  184. components: {
  185. infoPage
  186. },
  187. data () {
  188. return {
  189. //上传相关
  190. uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
  191. headers: {
  192. Authorization:getToken(),
  193. },
  194. tableButtonType:this.hasPermiDom(['iot:hardwareType:edit','iot:hardwareType:del',]),
  195. //页面状态
  196. pageType:1,
  197. //页面遮罩
  198. loading:false,
  199. //下拉列表数据
  200. optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
  201. keyOptionList:[],
  202. //查询条件
  203. queryParams:{
  204. page:1,
  205. pageSize:20,
  206. searchValue:"",
  207. state :null,
  208. },
  209. //列表数据
  210. dataList:[],
  211. //数据数量
  212. total:0,
  213. //组件传参
  214. propsData:{},
  215. //弹窗相关
  216. dialogTitle:'',
  217. dialogType:false,
  218. dialogForm:{},
  219. dialogRules:{
  220. hardwareTypeName: [
  221. { required: true, message: "请输入名称", trigger: "blur" },
  222. { required: true, message: "请输入名称", validator: this.spaceJudgment, trigger: "blur" }
  223. ],
  224. hardwareTypeKey: [
  225. { required: true, message: "请输入标识", trigger: "blur" },
  226. { required: true, message: "请输入标识", validator: this.spaceJudgment, trigger: "blur" }
  227. ],
  228. state: [
  229. { required: true, message: "请选择状态", trigger: "blur" },
  230. { required: true, message: "请选择状态", validator: this.spaceJudgment, trigger: "blur" }
  231. ],
  232. },
  233. //物联分类下拉列表
  234. iotTypeOptions:[],
  235. }
  236. },
  237. created () {
  238. },
  239. mounted () {
  240. this.iotTypeGetAllTypes();
  241. this.iotHardwareTypeGetTypeKey();
  242. this.getList();
  243. },
  244. methods: {
  245. //硬件选中
  246. hardwareChange(val){
  247. let self = this;
  248. this.keyOptionList.forEach((item) => {
  249. if(val == item.code){
  250. self.$set(self.dialogForm,'hardwareTypeKey',item.code);
  251. self.$set(self.dialogForm,'hardwareTypeName',item.name);
  252. }
  253. });
  254. },
  255. //物联选中
  256. deviceChange(val){
  257. let self = this;
  258. if(val){
  259. this.iotTypeOptions.forEach((item) => {
  260. if(val == item.typeKey){
  261. self.$set(self.dialogForm,'deviceTypeId',item.typeId);
  262. self.$set(self.dialogForm,'deviceTypeKey',item.typeKey);
  263. self.$set(self.dialogForm,'deviceTypeName',item.typeName);
  264. }
  265. });
  266. }else{
  267. this.$set(this.dialogForm,'deviceTypeId','');
  268. this.$set(this.dialogForm,'deviceTypeKey','');
  269. this.$set(this.dialogForm,'deviceTypeName','');
  270. }
  271. },
  272. //获取物联分类下拉列表
  273. iotTypeGetAllTypes(){
  274. iotTypeGetAllTypes({}).then(response => {
  275. this.$set(this,'iotTypeOptions',response.data);
  276. });
  277. },
  278. //查询按钮
  279. handleQuery(){
  280. this.$set(this.queryParams,'page',1);
  281. this.getList();
  282. },
  283. //重置按钮
  284. resetQuery(){
  285. this.$set(this,'queryParams',{
  286. page:1,
  287. pageSize:20,
  288. searchValue:"",
  289. state :null,
  290. });
  291. this.getList();
  292. },
  293. //获取数据列表
  294. getList(){
  295. this.$set(this,'loading',true);
  296. let obj = JSON.parse(JSON.stringify(this.queryParams))
  297. iotHardwareTypeList(obj).then(response => {
  298. this.$set(this,'loading',false);
  299. this.$set(this,'dataList',response.data.records);
  300. this.$set(this,'total',response.data.total);
  301. });
  302. },
  303. //操作按钮
  304. tableButton(type,row){
  305. let self = this;
  306. if(type == 2){
  307. //详情
  308. this.$set(this,'propsData',JSON.parse(JSON.stringify(row)));
  309. this.$set(this,'pageType',2);
  310. }if(type == 3){
  311. //编辑
  312. this.$set(this, 'dialogTitle', '编辑')
  313. let obj = JSON.parse(JSON.stringify(row))
  314. this.$set(this,'dialogForm',obj);
  315. this.$set(this,'dialogType',true);
  316. }else if(type == 4){
  317. //删除
  318. this.$confirm('是否确认删除?', "警告", {
  319. confirmButtonText: "确定",
  320. cancelButtonText: "取消",
  321. type: "warning"
  322. }).then(function() {
  323. }).then(() => {
  324. iotHardwareTypeDelete({hardwareTypeId:row.hardwareTypeId}).then(response => {
  325. self.msgSuccess(response.message)
  326. self.getList();
  327. });
  328. }).catch(() => {});
  329. }else if(type == 5){
  330. //启用&停用
  331. let text = row.state ? "停用" : "启用";
  332. this.$confirm('是否确认' + text + '?', "警告", {
  333. confirmButtonText: "确定",
  334. cancelButtonText: "取消",
  335. type: "warning"
  336. }).then(function() {
  337. }).then(() => {
  338. iotHardwareTypeUpdate({hardwareTypeId:row.hardwareTypeId,state:!row.state,}).then(response => {
  339. self.msgSuccess(response.message)
  340. self.getList();
  341. });
  342. }).catch(() => {});
  343. }else if(type == 6){
  344. //返回并刷新
  345. this.$set(this,'pageType',1);
  346. this.getList();
  347. }
  348. },
  349. //获取分类标识
  350. iotHardwareTypeGetTypeKey(){
  351. iotHardwareTypeGetTypeKey({}).then(response => {
  352. this.$set(this,'keyOptionList',response.data);
  353. });
  354. },
  355. //**************************弹窗相关**************************
  356. //弹层关闭
  357. dialogOff(){
  358. this.$set(this,'dialogType',false);
  359. },
  360. //弹层新增
  361. dialogFormReset(){
  362. this.$set(this,'dialogTitle','新增');
  363. this.$set(this,'dialogForm',{
  364. hardwareTypeName:"",
  365. hardwareTypeKey:"",
  366. deviceTypeId:"",
  367. deviceTypeName:"",
  368. deviceTypeKey:"",
  369. state:"",
  370. icon:"",
  371. exceptionIcon:"",
  372. });
  373. this.$set(this,'dialogType',true);
  374. },
  375. //dialog提交按钮
  376. dialogSubmit(){
  377. this.$refs["dialogForm"].validate(valid => {
  378. if (valid) {
  379. let obj = {
  380. hardwareTypeName:this.dialogForm.hardwareTypeName,
  381. hardwareTypeKey:this.dialogForm.hardwareTypeKey,
  382. deviceTypeId:this.dialogForm.deviceTypeId,
  383. deviceTypeName:this.dialogForm.deviceTypeName,
  384. deviceTypeKey:this.dialogForm.deviceTypeKey,
  385. state:this.dialogForm.state,
  386. icon:this.dialogForm.icon,
  387. exceptionIcon:this.dialogForm.icon,
  388. }
  389. if(this.dialogForm.hardwareTypeId){
  390. obj.hardwareTypeId = this.dialogForm.hardwareTypeId;
  391. iotHardwareTypeUpdate(obj).then(response => {
  392. this.msgSuccess(response.message)
  393. this.dialogOff();
  394. this.getList();
  395. });
  396. }else{
  397. iotHardwareTypeAdd(obj).then(response => {
  398. this.msgSuccess(response.message)
  399. this.dialogOff();
  400. this.getList();
  401. });
  402. }
  403. }
  404. })
  405. },
  406. //图片上传相关
  407. handleAvatarSuccess(res,type) {
  408. if(type == 'icon'){
  409. this.$set(this.dialogForm,'icon',res.data.url);
  410. }else if(type == 'exceptionIcon'){
  411. this.$set(this.dialogForm,'exceptionIcon',res.data.url);
  412. }
  413. },
  414. beforeAvatarUpload(file) {
  415. return new Promise((resolve, reject) => {
  416. if (file.type == 'image/svg+xml') {
  417. resolve()
  418. }else{
  419. this.$message.error('只能上传svg格式图片');
  420. reject();
  421. }
  422. })
  423. },
  424. },
  425. }
  426. </script>
  427. <style scoped lang="scss">
  428. .hardwareClassification{
  429. .hardwareClassificationPage{
  430. }
  431. }
  432. </style>