dialogComponent.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. v-model="showDialog"
  5. @open="open()"
  6. @close="closeDialog(0)"
  7. >
  8. <el-form
  9. ref="formInfo"
  10. :model="form"
  11. class="demo-form-inline aaa"
  12. label-width="150px"
  13. :rules="rules"
  14. >
  15. <el-form-item
  16. label="模板名称:"
  17. prop="platformName"
  18. v-if="dialogTitle == '添加模板'"
  19. >
  20. <el-input v-model="form.platformName"></el-input>
  21. </el-form-item>
  22. <el-form-item label="" prop="aa">
  23. <el-tree
  24. v-if="data.length"
  25. :data="data"
  26. :props="defaultProps"
  27. @node-click="handleNodeClick"
  28. show-checkbox
  29. node-key="id"
  30. :default-checked-keys="checkedArr"
  31. :check-strictly="isStrictly"
  32. @check="currentChecked"
  33. />
  34. </el-form-item>
  35. <br />
  36. <div style="text-align: right">
  37. <el-button @click="closeDialog(0)">取消</el-button>
  38. <el-button type="primary" @click="submitForm()">保存</el-button>
  39. </div>
  40. </el-form>
  41. </el-dialog>
  42. </template>
  43. <script>
  44. // 地图
  45. import AMap from 'AMap'
  46. import { useStore } from 'vuex'
  47. import { defineComponent, ref, watchEffect, onMounted } from 'vue'
  48. import * as api from '@/api/platManage/index.js'
  49. import { ElMessage } from 'element-plus'
  50. export default defineComponent({
  51. name: 'DialogComponent',
  52. emits: ['closeDialog'],
  53. props: {
  54. show_Dialog: Boolean,
  55. dialogTitle: String,
  56. itemInfo: {
  57. type: Object,
  58. default: function () {
  59. return {}
  60. },
  61. },
  62. },
  63. setup(props, { emit }) {
  64. const store = useStore()
  65. const beginTime = ref('')
  66. const showDialog = ref(false)
  67. const form = ref({})
  68. const formInfo = ref(null)
  69. const nowDate = ref(new Date().getTime())
  70. const data = ref([])
  71. const checkedArr = ref([])
  72. const getPlatformBoxList = ref([])
  73. const roleValid = (rule, value, callback) => {
  74. rule
  75. if (value.length === 0) {
  76. callback(new Error('角色不能为空'))
  77. } else {
  78. callback()
  79. }
  80. }
  81. const disabledDate = (time) => {
  82. return time.getTime() < Date.now()
  83. }
  84. const currentChecked = (nodeObj, SelectedObj) => {
  85. nodeObj, SelectedObj
  86. console.log('SelectedObj.checkedNodes')
  87. console.log(SelectedObj.checkedNodes)
  88. checkedArr.value = []
  89. SelectedObj.checkedNodes.forEach((item) => {
  90. checkedArr.value.push(item.id)
  91. })
  92. console.log(checkedArr.value)
  93. }
  94. //树结构回显
  95. function getPlatformMenu() {
  96. var platformId = ''
  97. if (props.dialogTitle == '添加模板') {
  98. platformId = 0
  99. } else {
  100. platformId = form.value.id
  101. }
  102. api
  103. .getPlatformMenu({
  104. platformId: platformId,
  105. })
  106. .then((requset) => {
  107. if (requset.status === 'SUCCESS') {
  108. console.log('requset.data111')
  109. console.log(requset.data)
  110. var jsona = JSON.stringify(requset.data.menus)
  111. var jsonb = jsona.replace(/"menu"/g, '"label"')
  112. jsonb = jsonb.replace(/"authority"/g, '"children"')
  113. jsonb = jsonb.replace(/"name"/g, '"label"')
  114. var jsonc = JSON.parse(jsonb)
  115. data.value = jsonc
  116. console.log('data.value')
  117. console.log(data.value)
  118. checkedArr.value = requset.data.checkedKeys
  119. console.log('checkedArr.value')
  120. console.log(checkedArr.value)
  121. } else {
  122. ElMessage.error(requset.msg)
  123. }
  124. })
  125. }
  126. // 保存操作
  127. const submitForm = () => {
  128. formInfo.value.validate((valid) => {
  129. if (valid) {
  130. var params = {}
  131. if (props.dialogTitle == '添加模板') {
  132. params = {
  133. platformId: 0,
  134. platformName: form.value.platformName,
  135. menuIds: checkedArr.value,
  136. }
  137. } else {
  138. params = {
  139. platformId: form.value.id,
  140. menuIds: checkedArr.value,
  141. }
  142. }
  143. if (checkedArr.value.length) {
  144. api.updatePlatformMenu(params).then((requset) => {
  145. if (requset.status === 'SUCCESS') {
  146. ElMessage.success({
  147. message: '新增成功',
  148. type: 'success',
  149. })
  150. showDialog.value = false
  151. // closeDialog()
  152. } else {
  153. ElMessage.error(requset.msg)
  154. }
  155. })
  156. } else {
  157. ElMessage.warning('请至少选择一个权限保存')
  158. }
  159. } else {
  160. console.log('error submit!!')
  161. return false
  162. }
  163. })
  164. }
  165. const marker = ref([])
  166. function initMap() {
  167. // AMap start
  168. var map = new AMap.Map('mapF', {
  169. resizeEnable: true,
  170. })
  171. //为地图注册click事件获取鼠标点击出的经纬度坐标
  172. var marker = new AMap.Marker({})
  173. map.on('click', function (e) {
  174. form.value.geoPosition = e.lnglat.getLng() + ',' + e.lnglat.getLat()
  175. map.remove([marker])
  176. marker = new AMap.Marker({
  177. position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  178. })
  179. map.add([marker])
  180. })
  181. // AMap end
  182. }
  183. const open = () => {
  184. form.value = props.itemInfo
  185. console.log('form.value')
  186. console.log(form.value)
  187. // optionselect()
  188. getPlatformMenu()
  189. }
  190. // 关闭弹框
  191. const closeDialog = (flag) => {
  192. checkedArr.value = []
  193. resetForm()
  194. showDialog.value = false
  195. emit('closeDialog', flag)
  196. }
  197. function resetForm() {
  198. formInfo.value.resetFields()
  199. }
  200. watchEffect((fn, options) => {
  201. fn, options
  202. showDialog.value = props.show_Dialog
  203. })
  204. //禁止选择以前的时间
  205. const pickerEndDate = (time) => {
  206. const timeRange = 1 * 24 * 60 * 60 * 1000
  207. return time.getTime() <= Date.now() - timeRange * 1
  208. }
  209. onMounted(() => {})
  210. return {
  211. pickerEndDate,
  212. roleValid,
  213. submitForm,
  214. closeDialog,
  215. open,
  216. data,
  217. getPlatformMenu,
  218. // map123,
  219. store,
  220. beginTime,
  221. showDialog,
  222. checkedArr,
  223. initMap,
  224. nowDate,
  225. disabledDate,
  226. marker,
  227. checked: true,
  228. form,
  229. formInfo,
  230. getPlatformBoxList,
  231. currentChecked,
  232. rules: {
  233. platformName: [
  234. { required: true, message: '请输入模板名称', trigger: 'blur' },
  235. {
  236. min: 1,
  237. max: 30,
  238. message: '长度在 1 到 30个字符',
  239. trigger: 'blur',
  240. },
  241. ],
  242. },
  243. }
  244. },
  245. })
  246. </script>
  247. <style scoped lang="scss">
  248. .el-input,
  249. .el-select,
  250. .el-date-editor.el-input,
  251. .el-date-editor.el-input__inner {
  252. width: 240px;
  253. }
  254. .el-form-item {
  255. margin: 0 0 20px !important;
  256. }
  257. // label样式
  258. .el-form-item__label {
  259. width: 120px !important;
  260. }
  261. .el-form-item__content {
  262. margin-left: 100px;
  263. }
  264. .demo-form-inline .el-form-item:not(.user-layout .el-form-item) {
  265. margin: 0 auto 20px 55px;
  266. }
  267. </style>
  268. <style lang="scss">
  269. // .aaa{
  270. // .el-form-item:not(.user-layout .el-form-item){
  271. // width:90%;
  272. // max-width:100%
  273. // }
  274. // .el-tree>.el-tree-node>.el-tree-node__children .el-tree-node {
  275. // display:inline-block
  276. // }
  277. // .el-tree>.el-tree-node{
  278. // display:block
  279. // }
  280. // }
  281. </style>