UserClientForm.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <Dialog v-model="dialogVisible" :title="dialogTitle" max-height="560px" width="900px" scroll>
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="关联系统">
  12. <el-select v-model="clientId" placeholder="请选择关联系统" style="width: 300px;">
  13. <el-option
  14. v-for="item in clientList"
  15. :key="item.id"
  16. :label="item.name"
  17. :value="item.id!"
  18. />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button
  23. type="primary"
  24. plain
  25. v-hasPermi="['system:user-client:create']"
  26. @click="submitForm"
  27. >
  28. 添加
  29. </el-button>
  30. </el-form-item>
  31. </el-form>
  32. </ContentWrap>
  33. <ContentWrap>
  34. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  35. <el-table-column label="关联系统" align="center" prop="clientName" />
  36. <el-table-column label="账户同步" align="center" prop="syncStatus" >
  37. <template #default="scope">
  38. <dict-tag :type="DICT_TYPE.SYNC_USER_STATUS" :value="scope.row.syncStatus" />
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="关联状态" align="center" prop="status" >
  42. <template #default="scope">
  43. <el-switch
  44. v-model="scope.row.status"
  45. :active-value="0"
  46. :inactive-value="1"
  47. @click="handleStatusChange2(scope.row)"
  48. />
  49. <!-- <dict-tag :type="DICT_TYPE.APPLICATION_STATUS" :value="scope.row.status" />-->
  50. </template>
  51. </el-table-column>
  52. <!-- <el-table-column label="创建人" align="center" prop="creatorDesc" />-->
  53. <el-table-column
  54. label="创建时间"
  55. align="center"
  56. prop="createTime"
  57. :formatter="dateFormatter"
  58. width="180px"
  59. />
  60. <el-table-column label="操作" align="center">
  61. <template #default="scope">
  62. <el-button
  63. type="primary"
  64. @click="handleSync(scope.row)"
  65. v-show = "scope.row.syncStatus!=1"
  66. v-hasClient="[scope.row.clientId+'']"
  67. >
  68. 同步
  69. </el-button>
  70. <el-button
  71. type="primary"
  72. @click="handlerLink(scope.row.clientId)"
  73. v-show = "scope.row.syncStatus==1 && scope.row.permissionsLink==0"
  74. v-hasClient="[scope.row.clientId+'']"
  75. >
  76. 权限设置
  77. </el-button>
  78. <!-- <el-button-->
  79. <!-- link-->
  80. <!-- type="danger"-->
  81. <!-- @click="handleDelete(scope.row.id)"-->
  82. <!-- v-if = "scope.row.status==0"-->
  83. <!-- >-->
  84. <!-- 停用-->
  85. <!-- </el-button>-->
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. </ContentWrap>
  90. </Dialog>
  91. </template>
  92. <script setup lang="ts">
  93. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  94. import { CommonStatusEnum,ApplicationStatusEnum} from '@/utils/constants'
  95. import { defaultProps, handleTree } from '@/utils/tree'
  96. import * as PostApi from '@/api/system/post'
  97. import * as DeptApi from '@/api/system/dept'
  98. import * as UserApi from '@/api/system/user'
  99. import * as ClientApi from '@/api/system/oauth2/client'
  100. import { FormRules } from 'element-plus'
  101. import { UserClientApi, UserClientVO } from '@/api/system/userclient'
  102. import { dateFormatter } from '@/utils/formatTime'
  103. import * as authUtil from '@/utils/auth'
  104. defineOptions({ name: 'SystemUserClientForm' })
  105. const { t } = useI18n() // 国际化
  106. const message = useMessage() // 消息弹窗
  107. const dialogVisible = ref(false) // 弹窗的是否展示
  108. const dialogTitle = ref('') // 弹窗的标题
  109. const clientList = ref([] as ClientApi.OAuth2ClientVO[]) // 岗位列表
  110. const list = ref<UserClientVO[]>([]) // 列表的数据
  111. const loading = ref(true) // 列表的加载中
  112. const total = ref(0) // 列表的总页数
  113. const clientId = ref()
  114. const userId = ref()
  115. const queryParams = reactive({
  116. pageNo: 1,
  117. pageSize: 10,
  118. userId: undefined,
  119. clientId: undefined,
  120. syncStatus: undefined,
  121. status: undefined,
  122. additionalInformation: undefined,
  123. createTime: []
  124. })
  125. const handlerLink = async (id) =>{
  126. try {
  127. const linkUrl = await UserApi.getLinkInfo(id, authUtil.getAccessToken())
  128. console.log(linkUrl)
  129. if (linkUrl != "") {
  130. window.open(linkUrl);
  131. }
  132. }catch (error) {
  133. console.log(error);
  134. }
  135. }
  136. const clientParams = ref<UserClientVO>()
  137. const submitForm = async () => {
  138. if(clientId.value===undefined){
  139. message.error("未选择关联系统")
  140. return
  141. }
  142. clientParams.clientId = clientId.value
  143. clientParams.userId = userId.value
  144. clientParams.syncStatus = 0
  145. clientParams.status = 1
  146. await UserClientApi.createUserClient(clientParams)
  147. getList()
  148. message.success(t('common.createSuccess'))
  149. }
  150. /** 查询列表 */
  151. const getList = async () => {
  152. loading.value = true
  153. try {
  154. const data = await UserClientApi.getUserClientPage(queryParams)
  155. list.value = data.list
  156. total.value = data.total
  157. } finally {
  158. loading.value = false
  159. }
  160. }
  161. /** 打开弹窗 */
  162. const open = async (type: string, id?: number) => {
  163. clientId.value = undefined
  164. dialogVisible.value = true
  165. dialogTitle.value = t('action.' + type)+'用户应用关系'
  166. queryParams.pageNo = 1
  167. queryParams.userId = id
  168. userId.value = id
  169. getList()
  170. // 加载岗位列表
  171. clientList.value = await ClientApi.getSelfNoClientList(id)
  172. }
  173. /** 修改用户状态 */
  174. const handleStatusChange2 = async (row: UserClientVO) => {
  175. try {
  176. // 修改状态的二次确认
  177. const text = row.status === ApplicationStatusEnum.ENABLE ? '启用' : '停用'
  178. await message.confirm('确认要"' + text + '"用户应用关联关系吗?')
  179. // 发起修改状态
  180. await UserClientApi.updateUserClientStatus(row.id, row.status)
  181. // 刷新列表
  182. await getList()
  183. } catch {
  184. // 取消后,进行恢复按钮
  185. row.status =
  186. row.status === ApplicationStatusEnum.ENABLE ? ApplicationStatusEnum.DISABLE : ApplicationStatusEnum.ENABLE
  187. }
  188. }
  189. /** 修改用户状态 */
  190. const handleSync = async (row: UserClientVO) => {
  191. try {
  192. // 修改状态的二次确认
  193. const text = '同步'
  194. await message.confirm('确认要"' + text + '"用户信息吗?')
  195. // 发起修改状态
  196. await UserClientApi.syncUserInfo(row.userId, row.clientId)
  197. message.notifySuccess('同步成功')
  198. // 刷新列表
  199. await getList()
  200. } catch {
  201. }
  202. }
  203. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  204. </script>