createCanvasDialog.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <el-dialog
  3. class="create-dialog"
  4. title="新建画布"
  5. width="600px"
  6. :visible.sync="outerVisible"
  7. :close-on-click-modal="false"
  8. custom-class="createDialog"
  9. @close="closeModal"
  10. >
  11. <div class="dialog-bodys">
  12. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" label-position="top">
  13. <el-form-item label="所属楼层" prop="buildFloor">
  14. <el-cascader v-model="ruleForm.buildFloor" :options="buildFloorData" @change="handleChangeBuildFloor" size="small"></el-cascader>
  15. </el-form-item>
  16. <el-form-item label="名称" prop="name">
  17. <el-input v-model="ruleForm.name" placeholder="请输入名称" size="small"></el-input>
  18. </el-form-item>
  19. <el-form-item label="标签" prop="resource">
  20. <div class="tagContainer">
  21. <el-tag :key="tag" v-for="tag in dynamicTags" closable :disable-transitions="false" @close="handleClose(tag)">
  22. {{ tag }}
  23. </el-tag>
  24. <el-input
  25. class="input-new-tag"
  26. v-if="inputVisible"
  27. v-model="inputValue"
  28. ref="saveTagInput"
  29. size="small"
  30. @keyup.enter.native="handleInputConfirm"
  31. @blur="handleInputConfirm"
  32. :maxlength="10"
  33. >
  34. </el-input>
  35. <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加</el-button>
  36. </div>
  37. </el-form-item>
  38. <el-form-item label="所属文件夹" prop="folder">
  39. <el-select v-model="ruleForm.folder" multiple filterable allow-create default-first-option size="small">
  40. <el-option v-for="item in folderData" :key="item.id" :label="item.name" :value="item.name"> </el-option>
  41. </el-select>
  42. </el-form-item>
  43. </el-form>
  44. </div>
  45. <div slot="footer" class="dialog-footer">
  46. <el-button @click="resetForm('ruleForm')">取消</el-button>
  47. <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
  48. </div>
  49. </el-dialog>
  50. </template>
  51. <script>
  52. import { buildingQuery } from "@/api/datacenter";
  53. export default {
  54. components: {},
  55. data() {
  56. return {
  57. buttonStr: "",
  58. ruleForm: {
  59. buildFloor: [],
  60. name: "",
  61. folder: "",
  62. },
  63. rules: {
  64. buildFloor: [{ required: true, message: "请选择建筑楼层", trigger: "blur" }],
  65. name: [
  66. { required: true, message: "请输入名称", trigger: "blur" },
  67. { max: 10, message: "最长为10个文字", trigger: "blur" },
  68. ],
  69. folder: [{ required: true, message: "请选择所属文件夹", trigger: "blur" }],
  70. },
  71. buildFloorData: [],
  72. value: [],
  73. outerVisible: false,
  74. dynamicTags: [],
  75. inputValue: "",
  76. inputVisible: false,
  77. folderData: [
  78. {
  79. id: 1,
  80. name: "能源系统",
  81. updateName: "能源系统",
  82. checked: false,
  83. showInput: false,
  84. },
  85. {
  86. id: 2,
  87. name: "排水系统",
  88. updateName: "排水系统",
  89. checked: false,
  90. showInput: false,
  91. },
  92. {
  93. id: 3,
  94. name: "消防水系统",
  95. updateName: "消防水系统",
  96. checked: false,
  97. showInput: false,
  98. },
  99. {
  100. id: 4,
  101. name: "公共照明系统公共照明系统公共照明系统公共照明系统",
  102. updateName: "公共照明系统公共照明系统公共照明系统公共照明系统",
  103. checked: false,
  104. showInput: false,
  105. },
  106. {
  107. id: 5,
  108. name: "暖通空调系统",
  109. updateName: "暖通空调系统",
  110. checked: false,
  111. showInput: false,
  112. },
  113. ],
  114. };
  115. },
  116. created() {
  117. this.getBuildingFloorData();
  118. },
  119. methods: {
  120. showDialog() {
  121. this.outerVisible = true;
  122. },
  123. handleClose(tag) {
  124. this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
  125. },
  126. // 获取建筑楼层数据
  127. getBuildingFloorData() {
  128. const params = {}
  129. buildingQuery(params, res => {
  130. debugger
  131. console.log(res)
  132. })
  133. },
  134. // 切换建筑楼层
  135. handleChangeBuildFloor(val) {
  136. console.log(val);
  137. },
  138. showInput() {
  139. this.inputVisible = true;
  140. this.$nextTick((_) => {
  141. this.$refs.saveTagInput.$refs.input.focus();
  142. });
  143. },
  144. handleInputConfirm() {
  145. const inputValue = this.inputValue;
  146. if (inputValue) {
  147. this.dynamicTags.push(inputValue);
  148. }
  149. this.inputVisible = false;
  150. this.inputValue = "";
  151. },
  152. submitForm(formName) {
  153. this.$refs[formName].validate((valid) => {
  154. if (valid) {
  155. this.createDraftsGraph();
  156. } else {
  157. console.log("error submit!!");
  158. return false;
  159. }
  160. });
  161. },
  162. resetForm(formName) {
  163. this.dynamicTags = [];
  164. this.buttonStr = "";
  165. this.$refs[formName].resetFields();
  166. this.outerVisible = false;
  167. },
  168. // 创建拓扑图接口
  169. createDraftsGraph() {
  170. const pa = {
  171. content: [
  172. {
  173. name: this.ruleForm.name,
  174. label: this.dynamicTags,
  175. },
  176. ],
  177. };
  178. createGraph(pa).then((res) => {
  179. if (res.result == "success") {
  180. this.outerVisible = false;
  181. this.$message.success("创建成功");
  182. this.$router.push({
  183. name: "Editer",
  184. query: {
  185. graphId: res.entityList[0].graphId,
  186. id: res.entityList[0].id,
  187. categoryName: encodeURI(this.buttonStr),
  188. isPub: 0,
  189. },
  190. });
  191. } else {
  192. this.$message(res.message);
  193. }
  194. });
  195. },
  196. closeModal() {
  197. this.resetForm("ruleForm");
  198. },
  199. },
  200. };
  201. </script>
  202. <style lang="less" scoped>
  203. /deep/ .createDialog {
  204. /deep/ .el-dialog__header {
  205. border-bottom: 1px solid #f0f1f2ff;
  206. }
  207. /deep/ .el-dialog__body {
  208. padding: 16px 120px;
  209. max-height: 500px;
  210. overflow: auto;
  211. }
  212. .el-dialog__footer {
  213. padding: 0 20px 20px;
  214. .el-button {
  215. padding: 0;
  216. width: 80px;
  217. height: 32px;
  218. text-align: center;
  219. line-height: 1;
  220. }
  221. }
  222. .el-form-item {
  223. margin-bottom: 0;
  224. & + .el-form-item {
  225. margin-top: 18px;
  226. }
  227. }
  228. .el-form-item__label {
  229. line-height: 1;
  230. }
  231. .el-tag {
  232. background: #eff0f1;
  233. border-radius: 2px;
  234. color: #1f2429ff;
  235. margin: 0 8px 8px 0;
  236. padding: 5px 6px 5px 8px;
  237. font-size: 14px;
  238. height: 24px;
  239. line-height: 1;
  240. border: none;
  241. &:hover {
  242. border: none;
  243. }
  244. .el-icon-close {
  245. color: #9ca2a9ff;
  246. right: 0;
  247. &:hover {
  248. color: #fff;
  249. background-color: #ccc;
  250. }
  251. }
  252. }
  253. .input-new-tag {
  254. width: 150px;
  255. // input{
  256. // height: 24px;
  257. // }
  258. }
  259. .button-new-tag {
  260. width: 60px;
  261. height: 24px;
  262. margin-bottom: 8px;
  263. padding: 0;
  264. line-height: 1;
  265. border-radius: 2px;
  266. border: 1px dotted #0091ff;
  267. color: #0091ff;
  268. &:hover {
  269. background: #fff;
  270. color: #0091ff;
  271. border: 1px dotted #0091ff;
  272. }
  273. }
  274. .typeButton {
  275. min-width: 122px;
  276. height: 32px;
  277. text-align: center;
  278. line-height: 32px;
  279. border-radius: 4px;
  280. padding: 0;
  281. border: 1px solid #c3c6cb;
  282. }
  283. .tagContainer {
  284. width: 100%;
  285. border-radius: 4px;
  286. border: 1px solid #c3c6cb;
  287. padding: 7px 12px;
  288. line-height: 1;
  289. }
  290. }
  291. </style>