permission-menu-form.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-model="state.showDialog"
  5. destroy-on-close
  6. :title="title"
  7. draggable
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. width="600px"
  11. >
  12. <el-form :model="form" ref="formRef" size="default" label-width="80px">
  13. <el-row :gutter="35">
  14. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  15. <el-form-item label="应用" prop="label">
  16. <el-input v-model="state.app" clearable disabled />
  17. </el-form-item>
  18. </el-col>
  19. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  20. <el-form-item label="上级分组">
  21. <el-tree-select
  22. v-model="form.parentId"
  23. :data="permissionTreeData"
  24. node-key="id"
  25. check-strictly
  26. default-expand-all
  27. render-after-expand
  28. fit-input-width
  29. clearable
  30. class="w100"
  31. />
  32. </el-form-item>
  33. </el-col>
  34. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  35. <el-form-item label="视图">
  36. <el-tree-select
  37. v-model="form.viewId"
  38. :data="state.viewTreeData"
  39. node-key="id"
  40. :props="{ label: 'path' }"
  41. default-expand-all
  42. render-after-expand
  43. fit-input-width
  44. clearable
  45. filterable
  46. :filter-node-method="onViewFilterNode"
  47. class="w100"
  48. @current-change="onViewCurrentChange"
  49. >
  50. <template #default="{ data }">
  51. <span class="my-flex my-flex-between">
  52. <span>{{ data.label }}</span>
  53. <span class="my-line-1 my-ml-12" :title="data.path">
  54. {{ data.path }}
  55. </span>
  56. </span>
  57. </template>
  58. </el-tree-select>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  62. <el-form-item label="名称" prop="label" :rules="[{ required: true, message: '请输入名称', trigger: ['blur', 'change'] }]">
  63. <el-input v-model="form.label" clearable />
  64. </el-form-item>
  65. </el-col>
  66. <!-- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  67. <el-form-item label="路由地址" prop="path" :rules="[{ required: true, message: '请输入路由地址', trigger: ['blur', 'change'] }]">
  68. <el-input v-model="form.path" clearable />
  69. </el-form-item>
  70. </el-col>
  71. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  72. <el-form-item label="路由命名">
  73. <el-input v-model="form.name" clearable />
  74. </el-form-item>
  75. </el-col> -->
  76. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  77. <el-form-item label="图标" prop="icon">
  78. <my-select-icon v-model="form.icon" clearable />
  79. </el-form-item>
  80. </el-col>
  81. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  82. <el-form-item label="排序">
  83. <el-input-number v-model="form.sort" />
  84. </el-form-item>
  85. </el-col>
  86. <!-- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  87. <el-form-item label="启用">
  88. <el-switch v-model="form.enabled" />
  89. </el-form-item>
  90. </el-col>
  91. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  92. <el-form-item label="链接地址">
  93. <el-input v-model="form.link" clearable placeholder="内嵌/外链链接地址" />
  94. </el-form-item>
  95. </el-col>
  96. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  97. <el-form-item label="内嵌窗口">
  98. <el-switch v-model="form.isIframe" />
  99. </el-form-item>
  100. </el-col>
  101. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  102. <el-form-item label="缓存">
  103. <el-switch v-model="form.isKeepAlive" />
  104. </el-form-item>
  105. </el-col>
  106. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  107. <el-form-item label="固定">
  108. <el-switch v-model="form.isAffix" />
  109. </el-form-item>
  110. </el-col>
  111. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  112. <el-form-item label="隐藏">
  113. <el-switch v-model="form.hidden" />
  114. </el-form-item>
  115. </el-col>
  116. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  117. <el-form-item label="新窗口">
  118. <el-switch v-model="form.newWindow" />
  119. </el-form-item>
  120. </el-col>
  121. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  122. <el-form-item label="链接外显">
  123. <el-switch v-model="form.external" />
  124. </el-form-item>
  125. </el-col> -->
  126. </el-row>
  127. </el-form>
  128. <template #footer>
  129. <span class="dialog-footer">
  130. <el-button @click="onCancel" size="default">取 消</el-button>
  131. <el-button type="primary" @click="onSure" size="default" :loading="state.sureLoading">确 定</el-button>
  132. </span>
  133. </template>
  134. </el-dialog>
  135. </div>
  136. </template>
  137. <script lang="ts" setup name="admin/permission/permission-menu-form">
  138. import { reactive, toRefs, getCurrentInstance, ref, PropType, defineAsyncComponent } from 'vue'
  139. import { OauthView,OauthPermission,oauthPermissionDto } from '/@/api/admin/data-contracts'
  140. import { PermissionApi } from '/@/api/admin/Permission'
  141. import { ViewApi } from '/@/api/admin/View'
  142. import { listToTree } from '/@/utils/tree'
  143. import eventBus from '/@/utils/mitt'
  144. // 引入组件
  145. const MySelectIcon = defineAsyncComponent(() => import('/@/components/my-select-icon/index.vue'))
  146. defineProps({
  147. title: {
  148. type: String,
  149. default: '',
  150. },
  151. permissionTreeData: {
  152. type: Array as PropType<OauthPermission[]>,
  153. default: () => [],
  154. },
  155. })
  156. const { proxy } = getCurrentInstance() as any
  157. const formRef = ref()
  158. const state = reactive({
  159. showDialog: false,
  160. sureLoading: false,
  161. form: {} as oauthPermissionDto,
  162. viewTreeData: [] as OauthView[],
  163. app:''
  164. })
  165. const { form } = toRefs(state)
  166. const getViews = async (app) => {
  167. const appDate=await new PermissionApi().getApplyInfo({Name:app})
  168. const res = await new PermissionApi().getViewInfo({appid:appDate.data[0].id})
  169. res.data=res.data.map((item)=>{
  170. if(item.parentId===''||item.parentId===null){
  171. item.parentId=Number('0')
  172. item.type=1
  173. }
  174. item.parentId=Number(item.parentId)
  175. return item
  176. })
  177. if (res?.success && res.data && res.data.length > 0) {
  178. state.viewTreeData = listToTree(res.data) as OauthView[]
  179. } else {
  180. state.viewTreeData = []
  181. }
  182. }
  183. // 打开对话框
  184. const open = async (app:any,row: any = {}) => {
  185. state.app=app
  186. proxy.$modal.loading()
  187. await getViews(app)
  188. // if (row.id > 0) {
  189. // const res = await new PermissionApi().getPermissionInfo({appid:0,id: row.id}).catch(() => {
  190. // proxy.$modal.closeLoading()
  191. // })
  192. // if (res?.success) {
  193. // let formData = res.data as oauthPermissionDto
  194. // formData.parentId = formData.parentId && Number(formData.parentId) > 0 ? formData.parentId : undefined
  195. // state.form = formData
  196. // }
  197. // } else {
  198. // state.form = { icon: 'ele-Memo' } as oauthPermissionDto
  199. // }
  200. state.form=row
  201. proxy.$modal.closeLoading()
  202. state.showDialog = true
  203. }
  204. const onViewFilterNode = (value: string, data: OauthView) => {
  205. if (!value) return true
  206. return data.label?.indexOf(value) !== -1 || data.path?.indexOf(value) !== -1
  207. }
  208. const onViewCurrentChange = (data: OauthView) => {
  209. if (data) {
  210. if (!state.form.label) {
  211. state.form.label = data.label
  212. }
  213. if (!state.form.viewPath) {
  214. state.form.viewPath = '/' + data.path
  215. }
  216. }
  217. }
  218. // 取消
  219. const onCancel = () => {
  220. state.showDialog = false
  221. }
  222. // 确定
  223. const onSure = () => {
  224. formRef.value.validate(async (valid: boolean) => {
  225. if (!valid) return
  226. state.sureLoading = true
  227. let res = {} as any
  228. state.form.parentId = state.form.parentId && Number(state.form.parentId) > 0 ? state.form.parentId : undefined
  229. state.form.type=2
  230. const appData=await new PermissionApi().getApplyInfo({name:state.app})
  231. state.form.appID=appData.data[0].id
  232. console.log(state.form)
  233. if (state.form.id != undefined && state.form.id > 0) {
  234. res = await new PermissionApi().addAppPermission(state.form, { showSuccessMessage: true }).catch(() => {
  235. state.sureLoading = false
  236. })
  237. } else {
  238. res = await new PermissionApi().addAppPermission(state.form, { showSuccessMessage: true }).catch(() => {
  239. state.sureLoading = false
  240. })
  241. }
  242. state.sureLoading = false
  243. if (res?.success) {
  244. eventBus.emit('refreshPermission')
  245. state.showDialog = false
  246. }
  247. })
  248. }
  249. defineExpose({
  250. open,
  251. })
  252. </script>
  253. <style scoped lang="scss">
  254. .my-ml-12 {
  255. margin-left: 12px;
  256. }
  257. </style>