dialog.addDoorHost.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="edu-training-edit">
  3. <DialogCom :title="title" @close="onHide" :visible.sync="isShow" width="960px">
  4. <div class="page-body">
  5. <el-form :model="formData" :rules="formDataRules" size="small" ref="form" label-position="right"
  6. label-width="120px" label-prefix=":">
  7. <el-row>
  8. <el-col :span="12">
  9. <el-form-item label="机构名称">
  10. <org-tree :disabled="this.isEdit"
  11. v-model="formData.orgId"
  12. @defaultKey="getDefaultKey"
  13. @defaultOrg="getDefaultOrg"
  14. @click="clickTreeNode"
  15. :defaultCheckSub="false"
  16. :showCheckSub="false"
  17. wholeTree
  18. ref="orgTree"
  19. ></org-tree>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="12">
  23. <el-form-item prop="iotCode" label="所属主机">
  24. <el-select :disabled="this.isEdit"
  25. prop="iotCode"
  26. label="所属主机"
  27. v-model="formData.iotCode"
  28. placeholder="请选择所属主机"
  29. >
  30. <el-option
  31. v-for="dict in hostConnectList"
  32. :key="dict.value"
  33. :label="dict.key"
  34. :value="dict.value"
  35. />
  36. </el-select>
  37. </el-form-item>
  38. </el-col>
  39. </el-row>
  40. <el-row>
  41. <!-- 设备名称 -->
  42. <el-col :span="12">
  43. <el-form-item prop="deviceName" label="设备名称">
  44. <el-input
  45. v-model="formData.deviceName"
  46. :maxlength="32"
  47. placeholder="请输入设备名称"
  48. clearable
  49. />
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="12">
  53. <el-form-item label="设备类型" prop="deviceProduct">
  54. <el-select style="width: 100%" v-model="formData.deviceType" placeholder="请选择设备类型" :disabled="this.isEdit">
  55. <el-option
  56. v-for="item in deviceTypeList"
  57. :key="item.key"
  58. :label="item.label"
  59. :value="item.key"
  60. />
  61. </el-select>
  62. </el-form-item>
  63. </el-col>
  64. </el-row>
  65. <el-row>
  66. <el-col :span="12">
  67. <el-form-item label="设备品牌" prop="deviceBrand">
  68. <el-select style="width: 100%" v-model="formData.deviceBrand" placeholder="请选择设备品牌" :disabled="this.isEdit">
  69. <el-option
  70. v-for="item in brandList"
  71. :key="item.key"
  72. :label="item.value"
  73. :value="item.key"
  74. />
  75. </el-select>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="12">
  79. <el-form-item label="主机Ip" prop="serverIp">
  80. <el-input v-model="formData.serverIp" placeholder="请输入主机Ip"/>
  81. </el-form-item>
  82. </el-col>
  83. </el-row>
  84. <el-row>
  85. <el-col :span="24" prop="enable">
  86. <el-form-item label="启用">
  87. <el-radio-group v-model="formData.enable">
  88. <el-radio :label="0">启用</el-radio>
  89. <el-radio :label="1">禁用</el-radio>
  90. </el-radio-group>
  91. </el-form-item>
  92. </el-col>
  93. </el-row>
  94. </el-form>
  95. </div>
  96. <div slot="footer" class="dialog-footer">
  97. <el-button type="primary" @click="onSubmit">确 定</el-button>
  98. <el-button @click="onHide">取 消</el-button>
  99. <!-- <el-button type="primary" @click="onSave">保存</el-button>-->
  100. </div>
  101. </DialogCom>
  102. </div>
  103. </template>
  104. <script>
  105. import {mapMutations, mapState} from "vuex";
  106. import {
  107. addDvrHostDevice, brandList,
  108. dvrHostDeviceInfo,
  109. editDvrHostDevice, editNetHostDevice,
  110. getProductDisplayName, netHostDeviceInfo,
  111. updateDvrHostDevice
  112. } from "@/api/iot/deviceInfo";
  113. import KSelect from "@/components/common/userselect.vue";
  114. import OrgTree from "@/components/orgTree/orgQuerySelector.vue";
  115. import {addConfig, updateConfig} from "@/api/system/config";
  116. import * as iotApi from "@/api/iot/alarmRule";
  117. import {getCurOrgConnectHost} from "@/api/iot/alarmRule";
  118. export default {
  119. components: {KSelect, OrgTree},
  120. data() {
  121. const params = this.$route.params;
  122. return {
  123. id: params ? params.id : null,
  124. isShow: false,
  125. title: '',
  126. formData: this.reset(),
  127. deviceTypeList: [],
  128. modelList: [],
  129. hostConnectList: [],
  130. isEdit:false,
  131. brandList: [],
  132. formDataRules: {
  133. deviceName: [{required: true, message: "请输入设备名称", trigger: 'blur'}],
  134. deviceType: [{required: true, message: "请选择设备类型", trigger: 'blur'}],
  135. iotCode: [{required: true, message: "请选择所属主机", trigger: 'blur'}],
  136. deviceBrand: [{required: true, message: "请选择设备品牌", trigger: 'blur'}],
  137. serverIp: [
  138. {required: true, message: '请输入主机Ip', trigger: 'blur'},
  139. {validator: this.validateIp, trigger: 'blur'}
  140. ],
  141. },
  142. };
  143. },
  144. dicts: [],
  145. props: {},
  146. watch: {},
  147. created() {
  148. },
  149. mounted() {
  150. },
  151. computed: {
  152. ...mapState(["loginUser", "org"]),
  153. },
  154. methods: {
  155. ...mapMutations([]),
  156. reset(other = {}) {
  157. return {
  158. id: null,
  159. orgId: null,
  160. iotCode: null,
  161. deviceName: null,
  162. deviceType: null,
  163. serverIp: "",
  164. enable: 0,
  165. };
  166. },
  167. async refresh(id, other) {
  168. if (!id) {
  169. this.reset(other);
  170. }else {
  171. netHostDeviceInfo( id).then((response) => {
  172. this.formData =response.data;
  173. })
  174. }
  175. },
  176. async show(id,orgId, name, other = {}) {
  177. this.formData = this.reset(other);
  178. this.formData.orgId = orgId;
  179. this.title = '新增' + name;
  180. this.isEdit=false;
  181. this.initData();
  182. if (id){
  183. this.title = '编辑' + name;
  184. this.formData.id = id;
  185. this.isEdit=true;
  186. await this.refresh(id, other);
  187. }
  188. /*this.$nextTick(() => {
  189. this.$refs.form.clearValidate(); // 确保在 DOM 更新之后清除表单验证状态
  190. });*/
  191. this.isShow = true;
  192. },
  193. // 事件
  194. onHide() {
  195. this.isShow = false;
  196. this.formData = this.reset();
  197. /* this.$nextTick(() => {
  198. this.$refs.form.clearValidate(); // 确保在 DOM 更新之后清除表单验证状态
  199. });*/
  200. },
  201. async onSubmit() {
  202. this.$refs["form"].validate((valid) => {
  203. if (valid) {
  204. editNetHostDevice(this.formData).then(r => {
  205. if (!this.formData.id) {
  206. this.$modal.msgSuccess("新增成功");
  207. } else {
  208. this.$modal.msgSuccess("修改成功");
  209. }
  210. this.flushList();
  211. this.onHide();
  212. })
  213. }
  214. });
  215. },
  216. flushList(){
  217. setTimeout(() => {
  218. this.$emit("reload", this.formData);
  219. },200);
  220. },
  221. getDefaultOrg(org) {
  222. this.orgName = org.name;
  223. this.formData.orgId = org.id;
  224. },
  225. getDefaultKey(key) {
  226. this.formData.orgId = key;
  227. },
  228. // 节点单击事件
  229. clickTreeNode(data) {
  230. if (!data) {
  231. return;
  232. }
  233. this.formData.orgId = data.id;
  234. this.orgChange();
  235. },
  236. orgChange(){
  237. this.formData.iotCode = null;
  238. this.getConnectHostOrg();
  239. },
  240. getConnectHostOrg() {
  241. if (!this.formData.orgId) {
  242. return
  243. }
  244. iotApi.getCurOrgConnectHost(this.formData.orgId).then((response) => {
  245. this.hostConnectList = response.data;
  246. });
  247. },
  248. initBrand() {
  249. brandList("BrandModelType").then((response) => {
  250. this.brandList = response.data;
  251. });
  252. },
  253. initDeviceType(){
  254. this.deviceTypeList=[];
  255. this.deviceTypeList.push({key:'24',label:'门禁主机'});
  256. },
  257. initData(){
  258. this.getConnectHostOrg();
  259. this.initBrand();
  260. this.initDeviceType();
  261. },
  262. validateIp(rule, value, callback) {
  263. if (!value) {
  264. return callback(new Error('请输入服务Ip'));
  265. }
  266. const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
  267. if (!ipRegex.test(value)) {
  268. callback(new Error('服务Ip格式不正确'));
  269. } else {
  270. callback();
  271. }
  272. },
  273. },
  274. };
  275. </script>
  276. <!-- <style lang="scss" scoped>
  277. .k-textarea{
  278. .el-textarea {
  279. .el-textarea__inner {
  280. font-size: 15px !important;
  281. }
  282. }
  283. }
  284. </style> -->