index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <script lang="ts" setup name="OrgIndex">
  2. import { ElMessage, ElMessageBox } from 'element-plus'
  3. import OcComponent from '../components/Oc.vue'
  4. import OcAdminComponent from '../components/OcAdmin.vue'
  5. import { deleteOcById, getOcByList, resetAdminPwd, updateLicStatus, updateStatus } from '@/api/system/ocApi'
  6. import { ocTypeFilter } from '@/utils/tool'
  7. const state = reactive({
  8. loading: false,
  9. // 表格是否自适应高度
  10. tableAutoHeight: false,
  11. // 搜索
  12. search: {
  13. ocTypeId: 3,
  14. keywords: '',
  15. },
  16. // 列表数据
  17. dataList: [],
  18. })
  19. const ocRef = ref()
  20. const getDataList = async () => {
  21. state.loading = true
  22. const { data } = await getOcByList(state.search)
  23. state.dataList = data
  24. state.loading = false
  25. }
  26. onMounted(() => {
  27. getDataList()
  28. })
  29. function onSearch() {
  30. getDataList()
  31. }
  32. function onOcAdd() {
  33. const ocTypeId = state.search.ocTypeId
  34. ocRef.value.showAddModel(ocTypeId)
  35. }
  36. function onOcEdit(row: any) {
  37. const ocId = row.ocId
  38. ocRef.value.showEditModel(ocId)
  39. }
  40. function onOcDel(row: any) {
  41. ElMessageBox.confirm(`确认删除「${row.ocName}」吗?`, '确认信息').then(async () => {
  42. await deleteOcById(row.ocId)
  43. await getDataList()
  44. ElMessage.success({
  45. message: '删除成功',
  46. center: true,
  47. })
  48. }).catch(() => {})
  49. }
  50. const ocAdminRef = ref()
  51. // 添加管理员账号
  52. function onAdminAdd(row: any) {
  53. const { ocId } = row
  54. ocAdminRef.value.showAddModel(ocId)
  55. }
  56. // 修改管理员账号
  57. function onAdminEdit(row: any) {
  58. const { ocId } = row
  59. ocAdminRef.value.showEditModel(ocId)
  60. }
  61. // 状态变更
  62. const onStatusChange = async (status: number, row: { ocId: number }) => {
  63. const { msg } = await updateStatus(row.ocId, status)
  64. ElMessage.success(msg)
  65. }
  66. // license状态变更
  67. const onLicStatusChange = async (status: number, row: { ocId: number }) => {
  68. const { msg } = await updateLicStatus(row.ocId, status)
  69. ElMessage.success(msg)
  70. }
  71. function onPasswordReset(row: { ocId: number; adminId: number; adminName: string }) {
  72. ElMessageBox.confirm(`确认删除「${row.adminName}」吗?`, '确认信息').then(async () => {
  73. const { ocId, adminId } = row
  74. const { msg } = await resetAdminPwd(ocId, adminId)
  75. ElMessage.success(msg)
  76. }).catch(() => {})
  77. }
  78. </script>
  79. <template>
  80. <div :class="{ 'absolute-container': state.tableAutoHeight }">
  81. <page-header title="政府机构管理" />
  82. <page-main>
  83. <tool-bar>
  84. <template #right>
  85. <el-input v-model="state.search.keywords" placeholder="请输入名称,支持模糊查询" style="padding-right: 10px;" clearable />
  86. <el-button type="primary" @click="onSearch">
  87. <template #icon>
  88. <el-icon>
  89. <svg-icon name="i-ep:search" />
  90. </el-icon>
  91. </template>
  92. </el-button>
  93. <el-button size="default" @click.stop="onOcAdd">
  94. <template #icon>
  95. <el-icon>
  96. <svg-icon name="i-ep:plus" />
  97. </el-icon>
  98. </template>
  99. 公司单位
  100. </el-button>
  101. </template>
  102. </tool-bar>
  103. <el-table v-loading="state.loading" class="list-table" :data="state.dataList" size="small" border stripe highlight-current-row height="100%">
  104. <el-table-column type="index" label="序号" width="60" header-align="center" align="center" />
  105. <el-table-column prop="ocName" label="名称" header-align="center" align="center" width="200">
  106. <template #default="scope">
  107. <span>{{ scope.row.ocName }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column prop="ocTypeId" label="类型" header-align="center" align="center" width="120">
  111. <template #default="scope">
  112. <span>{{ ocTypeFilter(scope.row.ocTypeId) }}</span>
  113. </template>
  114. </el-table-column>
  115. <el-table-column prop="ocCatId" label="分类" header-align="center" align="center" width="120">
  116. <template #default="scope">
  117. <span>{{ scope.row.ocCatTitle }}</span>
  118. </template>
  119. </el-table-column>
  120. <el-table-column prop="ocRemark" label="备注" header-align="center" align="left">
  121. <template #default="scope">
  122. <span>{{ scope.row.ocRemark }}</span>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="管理员账号" header-align="center" align="center" width="150">
  126. <template #default="scope">
  127. <div>
  128. <el-tag v-if="scope.row.adminId > 0" @click="onAdminEdit(scope.row)">
  129. {{ scope.row.adminName }}
  130. </el-tag>
  131. <el-tag v-else @click="onAdminAdd(scope.row)">
  132. <i class="el-icon-plus" /> 管理员账号
  133. </el-tag>
  134. </div>
  135. </template>
  136. </el-table-column>
  137. <el-table-column align="center" label="License控制" width="120">
  138. <template #default="scope">
  139. <div v-if="scope.row.isFixed !== 1">
  140. <el-switch
  141. v-model="scope.row.status"
  142. :active-value="1"
  143. :inactive-value="0"
  144. :loading="scope.row.loading"
  145. inline-prompt
  146. active-text="启用"
  147. inactive-text="禁用"
  148. @change="(status) => onStatusChange(scope.row.status, scope.row)"
  149. />
  150. </div>
  151. </template>
  152. </el-table-column>
  153. <el-table-column align="center" label="状态" width="120">
  154. <template #default="scope">
  155. <div v-if="scope.row.isFixed !== 1">
  156. <el-switch
  157. v-model="scope.row.ifLic"
  158. :active-value="1"
  159. :inactive-value="0"
  160. :loading="scope.row.loading"
  161. inline-prompt
  162. active-text="启用"
  163. inactive-text="禁用"
  164. @change="(status) => onLicStatusChange(scope.row.status, scope.row)"
  165. />
  166. </div>
  167. </template>
  168. </el-table-column>
  169. <el-table-column label="操作" header-align="center" align="center" width="220">
  170. <template #default="scope">
  171. <el-button type="primary" size="small" plain @click="onOcEdit(scope.row)">
  172. 编辑
  173. </el-button>
  174. <el-button v-if="!scope.row.isFixed" type="danger" size="small" plain @click="onOcDel(scope.row)">
  175. 删除
  176. </el-button>
  177. <el-button v-if="!scope.row.adminId > 0" type="danger" size="small" plain @click="onPasswordReset(scope.row)">
  178. 重置管理员密码
  179. </el-button>
  180. </template>
  181. </el-table-column>
  182. </el-table>
  183. </page-main>
  184. <OcComponent ref="ocRef" @success="getDataList" />
  185. <OcAdminComponent ref="ocAdminRef" @success="getDataList" />
  186. </div>
  187. </template>
  188. <style lang="scss" scoped>
  189. .absolute-container {
  190. position: absolute;
  191. width: 100%;
  192. height: 100%;
  193. display: flex;
  194. flex-direction: column;
  195. .page-header {
  196. margin-bottom: 0;
  197. }
  198. .page-main {
  199. // 让 page-main 的高度自适应
  200. flex: 1;
  201. overflow: auto;
  202. display: flex;
  203. flex-direction: column;
  204. .search-container {
  205. margin-bottom: 0;
  206. }
  207. }
  208. }
  209. </style>