index.vue 6.9 KB

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