index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div v-show="!showCount" class="dept-user-com-box dept-info">
  3. <div class="di-left">
  4. <h3>{{ deptInfo.dept_name || '' }}</h3>
  5. <div class="di-cell">
  6. <p>部门负责人:</p>
  7. <p class="content">{{ deptInfo.owner || '无' }}</p>
  8. </div>
  9. <div class="di-cell">
  10. <p>部门人数:</p>
  11. <p class="content">{{ deptInfo.dept_user || 0 }}人</p>
  12. </div>
  13. <div class="di-cell">
  14. <p>部门简介:</p>
  15. <p class="content">{{ deptInfo.description || '无' }}</p>
  16. </div>
  17. <div class="di-cell">
  18. <p>显示子级:</p>
  19. <el-switch
  20. v-model="isShowChildFlag"
  21. inline-prompt
  22. active-text="是"
  23. inactive-text="否"
  24. :disabled="!currentDeptId"
  25. @change="handleSwitchChange"
  26. style="--el-switch-on-color: var(--el-color-primary)"
  27. />
  28. </div>
  29. </div>
  30. <div style="height: 180px; width: 380px" ref="deptCountBar"></div>
  31. <div style="height: 180px; width: 200px" ref="deptSexPie"></div>
  32. </div>
  33. <fs-crud
  34. ref="crudRef"
  35. v-bind="crudBinding"
  36. :customClass="!showCount ? 'dept-user-com-box dept-user-com-table' : 'dept-user-com-box dept-user-com-table-cover'"
  37. >
  38. <template #toolbar-left>
  39. <el-button :icon="!showCount ? 'Hide' : 'View'" circle @click="showCount = !showCount"></el-button>
  40. </template>
  41. <template #actionbar-right>
  42. <importExcel api="api/system/user/">导入 </importExcel>
  43. <el-button class="ml-1" type="primary" @click="openDeptPermission" :disabled="!currentDeptId">部门权限</el-button>
  44. </template>
  45. </fs-crud>
  46. <DeptDialog v-if="createOpen" v-model="createOpen" :deptId="currentDeptId"></DeptDialog>
  47. </template>
  48. <script lang="ts" setup name="user">
  49. import { ref, onMounted } from 'vue';
  50. import { useExpose, useCrud } from '@fast-crud/fast-crud';
  51. import { createCrudOptions } from './crud';
  52. import importExcel from '/@/components/importExcel/index.vue';
  53. import * as echarts from 'echarts';
  54. import { ECharts, EChartsOption, init } from 'echarts';
  55. import { getDeptInfoById } from './api';
  56. import { HeadDeptInfoType } from '../../types';
  57. import { FormInstance } from 'element-plus';
  58. import DeptDialog from '/@/views/system/dept/components/DeptUserCom/component/deptDialog.vue';
  59. let deptCountChart: ECharts;
  60. let deptSexChart: ECharts;
  61. // crud组件的ref
  62. const crudRef = ref();
  63. // crud 配置的ref
  64. const crudBinding = ref();
  65. // 暴露的方法
  66. const { crudExpose } = useExpose({ crudRef, crudBinding });
  67. // const deptId = inject('deptId')
  68. const createOpen = ref(false);
  69. let currentDeptId = ref(1);
  70. let deptCountBar = ref();
  71. let deptSexPie = ref();
  72. let isShowChildFlag = ref(false);
  73. let deptInfo = ref<Partial<HeadDeptInfoType>>({});
  74. let showCount = ref(false);
  75. /**
  76. * 初始化顶部部门折线图
  77. */
  78. const initDeptCountBarChart = () => {
  79. const xAxisData = deptInfo.value.sub_dept_map?.map((item) => item.name) || [];
  80. const yAxisData = deptInfo.value.sub_dept_map?.map((item) => item.count) || [];
  81. const option: EChartsOption = {
  82. tooltip: {
  83. trigger: 'axis',
  84. axisPointer: {
  85. type: 'shadow',
  86. },
  87. },
  88. xAxis: {
  89. type: 'category',
  90. data: xAxisData,
  91. axisTick: {
  92. alignWithLabel: true,
  93. },
  94. },
  95. yAxis: {
  96. type: 'value',
  97. },
  98. dataZoom: [
  99. {
  100. type: 'inside',
  101. },
  102. ],
  103. grid: {
  104. top: '6%',
  105. right: '5%',
  106. bottom: '10%',
  107. left: '10%',
  108. },
  109. series: [
  110. {
  111. data: yAxisData,
  112. type: 'bar',
  113. barWidth: '60%',
  114. showBackground: true,
  115. itemStyle: {
  116. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  117. { offset: 0, color: '#83bff6' },
  118. { offset: 0.5, color: '#188df0' },
  119. { offset: 1, color: '#188df0' },
  120. ]),
  121. },
  122. },
  123. ],
  124. };
  125. deptCountChart.setOption(option);
  126. };
  127. /**
  128. * 初始化顶部性别统计
  129. */
  130. const initDeptSexPieChart = () => {
  131. const option: EChartsOption = {
  132. tooltip: {
  133. trigger: 'item',
  134. },
  135. legend: {
  136. orient: 'vertical',
  137. right: '0%',
  138. left: '65%',
  139. top: 'center',
  140. itemWidth: 12,
  141. itemHeight: 12,
  142. },
  143. series: [
  144. {
  145. type: 'pie',
  146. radius: '65%',
  147. center: ['32%', '50%'],
  148. label: {
  149. show: false,
  150. position: 'center',
  151. },
  152. color: ['#188df0', '#f56c6c', '#dcdfe6'],
  153. data: [
  154. { value: deptInfo.value.gender?.male || 0, name: '男' },
  155. { value: deptInfo.value.gender?.female || 0, name: '女' },
  156. { value: deptInfo.value.gender?.unknown || 0, name: '未知' },
  157. ],
  158. },
  159. ],
  160. };
  161. deptSexChart.setOption(option);
  162. };
  163. /**
  164. * 获取顶部部门信息
  165. */
  166. const getDeptInfo = async () => {
  167. const res = await getDeptInfoById(currentDeptId.value, isShowChildFlag.value ? '1' : '0');
  168. if (res?.code === 2000) {
  169. deptInfo.value = res.data;
  170. initDeptCountBarChart();
  171. initDeptSexPieChart();
  172. }
  173. };
  174. /**
  175. * 部门切换刷新用户列表
  176. */
  177. const handleDoRefreshUser = (id: string) => {
  178. currentDeptId.value = id;
  179. crudExpose.doSearch({ form: { dept: id } });
  180. getDeptInfo();
  181. };
  182. /**
  183. * 部门管理权限弹窗
  184. */
  185. const openDeptPermission = () => {
  186. createOpen.value = true;
  187. };
  188. const handleSwitchChange = () => {
  189. handleDoRefreshUser(currentDeptId.value);
  190. };
  191. onMounted(() => {
  192. crudExpose.doRefresh();
  193. deptCountChart = init(deptCountBar.value as HTMLElement);
  194. deptSexChart = init(deptSexPie.value as HTMLElement);
  195. getDeptInfo();
  196. });
  197. defineExpose({
  198. handleDoRefreshUser,
  199. });
  200. // 你的crud配置
  201. const { crudOptions } = createCrudOptions({ crudExpose, context: { getDeptInfo, isShowChildFlag } });
  202. // 初始化crud配置
  203. const { resetCrudOptions } = useCrud({
  204. crudExpose,
  205. crudOptions,
  206. context: {},
  207. });
  208. </script>
  209. <style lang="scss" scoped>
  210. .dept-user-com-box {
  211. padding: 0 10px;
  212. border-radius: 8px 0 0 8px;
  213. box-sizing: border-box;
  214. background-color: #fff;
  215. }
  216. .dept-user-com-table {
  217. height: calc(100% - 200px);
  218. }
  219. .dept-user-com-table-cover {
  220. height: 100%;
  221. }
  222. .dept-info {
  223. width: 100%;
  224. height: 200px;
  225. display: flex;
  226. align-items: center;
  227. justify-content: space-around;
  228. margin-bottom: 10px;
  229. .di-left {
  230. h3 {
  231. font-size: 18px;
  232. font-weight: 900;
  233. }
  234. .di-cell {
  235. margin-top: 6px;
  236. display: flex;
  237. align-items: center;
  238. p:nth-child(1) {
  239. display: block;
  240. width: 85px;
  241. text-align: left;
  242. }
  243. .content {
  244. max-width: 120px;
  245. overflow: hidden;
  246. white-space: nowrap;
  247. text-overflow: ellipsis;
  248. }
  249. }
  250. }
  251. }
  252. </style>