LeaderTeam.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div
  3. class="leader-team"
  4. :class="{
  5. 'leader-team--indent': props.teamData.level != 1,
  6. 'hide-arrow': props.teamData.level === 3,
  7. }"
  8. >
  9. <el-collapse-item :name="props.teamData.teamId">
  10. <template #title>
  11. <div
  12. class="leader-team__title"
  13. :class="{
  14. 'leader-team--selected': props.teamData.teamId === curTeam?.teamId,
  15. }"
  16. @click.stop
  17. @click="clickTeam"
  18. >
  19. <div class="leader-team__rename" v-show="showRenameTeamInput">
  20. <el-input
  21. v-model="inputNewTeamName"
  22. class="leader-team__rename-input"
  23. placeholder="为此队伍命名"
  24. maxlength="15"
  25. show-word-limit
  26. ref="teamNameInputRef"
  27. @blur="enterNewName"
  28. @keyup.enter="$event.target.blur()"
  29. />
  30. </div>
  31. <div v-show="!showRenameTeamInput" class="leader-team__team-name">
  32. {{ props.teamData.teamName }}
  33. </div>
  34. <div class="leader-team__menu-icon" @click.stop>
  35. <img src="@/assets/icons/nine-square-grid/more.png" @click="showTeamOperation = !showTeamOperation" />
  36. </div>
  37. <div
  38. v-show="showTeamOperation"
  39. class="leader-team__operation"
  40. :class="{ 'adjust-menu-position': props.teamData.level === 3 }"
  41. @click.stop
  42. >
  43. <div v-if="props.teamData.level !== 3" @mousedown="showAddTeamDialog()" class="leader-team__operation-item">
  44. 新建队伍
  45. </div>
  46. <div @click="handleDelete()" class="leader-team__operation-item"> 删除队伍 </div>
  47. </div>
  48. </div>
  49. </template>
  50. <div v-if="props.teamData.level <= 3">
  51. <div v-for="team in props.teamData.children" :key="team.teamId">
  52. <leaderTeam :team-data="team" :parent-id="props.teamData.teamId" @expand="emitExpandEvent" />
  53. </div>
  54. </div>
  55. </el-collapse-item>
  56. </div>
  57. <AddTeam ref="addTeamRef" @emit-team-name="handleCreate" />
  58. </template>
  59. <script setup lang="ts">
  60. import { ref, watch, nextTick } from 'vue';
  61. import { ElMessageBox } from 'element-plus';
  62. import { storeToRefs } from 'pinia';
  63. import AddTeam from './components/AddTeam.vue';
  64. import { LeaderTeamType } from '../type';
  65. import useTeamStore from '../store/userTeam';
  66. import { updateEmergencyTeamInfo } from '@/api/emergency-organization/teams';
  67. const props = defineProps<{
  68. teamData: LeaderTeamType;
  69. parentId: number;
  70. }>();
  71. const emit = defineEmits<{ (e: 'expand', collapseId: number) }>();
  72. const indentation = `${props.teamData.level * 10}px`;
  73. const { curTeam, loadingTeams } = storeToRefs(useTeamStore());
  74. const { getLeaderTeams, createTeam, deleteTeam, getSelectTeamInfo } = useTeamStore();
  75. const showTeamOperation = ref(false);
  76. const showRenameTeamInput = ref(false);
  77. const teamOriginName = ref(props.teamData.teamName);
  78. const inputNewTeamName = ref('');
  79. const teamNameInputRef = ref();
  80. const addTeamRef = ref<InstanceType<typeof AddTeam>>();
  81. function handleRenameTeam() {
  82. showRenameTeamInput.value = true;
  83. nextTick(() => {
  84. teamNameInputRef.value.focus();
  85. inputNewTeamName.value = teamOriginName.value;
  86. });
  87. }
  88. async function enterNewName() {
  89. if (inputNewTeamName.value === '' || inputNewTeamName.value === teamOriginName.value) {
  90. showRenameTeamInput.value = false;
  91. return;
  92. }
  93. loadingTeams.value = true;
  94. const data = { id: props.teamData.teamId, teamName: inputNewTeamName.value };
  95. await updateEmergencyTeamInfo(data);
  96. await getLeaderTeams();
  97. teamOriginName.value = inputNewTeamName.value;
  98. showRenameTeamInput.value = false;
  99. loadingTeams.value = false;
  100. }
  101. function showAddTeamDialog() {
  102. addTeamRef.value?.dialogShow();
  103. }
  104. function handleCreate(teamName: string) {
  105. createTeam(props.teamData, teamName);
  106. // 添加完成后展开队伍
  107. emitExpandEvent(props.teamData.teamId);
  108. }
  109. function handleDelete() {
  110. ElMessageBox.confirm('是否确认删除该队伍').then(async () => {
  111. deleteTeam(props.teamData);
  112. });
  113. }
  114. let clickTimeout: any = null;
  115. function clickTeam(event) {
  116. // 单击事件
  117. if (event.detail === 1) {
  118. clickTimeout = setTimeout(() => {
  119. getSelectTeamInfo(props.teamData);
  120. }, 200);
  121. }
  122. // 双击事件
  123. else if (event.detail === 2) {
  124. clearTimeout(clickTimeout);
  125. handleRenameTeam();
  126. }
  127. }
  128. // 控制新建/删除菜单的隐藏
  129. const closeTeamOperation = (event) => {
  130. if (event.target.className !== 'leader-team__operation-item') showTeamOperation.value = false;
  131. if (event.target.innerText === '新建队伍') {
  132. showTeamOperation.value = false;
  133. }
  134. };
  135. function emitExpandEvent(collapseId: number) {
  136. emit('expand', collapseId);
  137. }
  138. watch(
  139. () => showTeamOperation.value,
  140. (newValue) => {
  141. newValue
  142. ? document.addEventListener('mousedown', closeTeamOperation)
  143. : document.removeEventListener('mousedown', closeTeamOperation);
  144. },
  145. );
  146. </script>
  147. <style scoped lang="scss">
  148. .leader-team {
  149. .leader-team__title {
  150. height: 38px;
  151. width: 100%;
  152. min-width: 95px;
  153. display: flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. color: #333333;
  157. border-radius: 4px;
  158. position: relative;
  159. cursor: default;
  160. .leader-team__rename {
  161. height: 32px;
  162. width: 100%;
  163. display: flex;
  164. align-items: center;
  165. background-color: #1777ff;
  166. border-radius: 4px;
  167. font-size: 14px;
  168. line-height: 24px;
  169. padding-right: 6px;
  170. .leader-team__rename-input {
  171. height: 24px;
  172. }
  173. }
  174. .leader-team__team-name {
  175. white-space: nowrap;
  176. }
  177. .leader-team__menu-icon {
  178. visibility: hidden;
  179. margin-left: 10px;
  180. margin-right: 10px;
  181. img {
  182. height: 20px;
  183. width: 20px;
  184. &:hover {
  185. background-color: rgba(255, 255, 255, 0.2);
  186. border-radius: 4px;
  187. cursor: pointer;
  188. }
  189. }
  190. }
  191. &:hover .leader-team__menu-icon {
  192. visibility: visible;
  193. display: flex;
  194. align-items: center;
  195. }
  196. .leader-team__operation {
  197. display: block;
  198. width: 130px;
  199. position: absolute;
  200. bottom: -63px;
  201. right: 5px;
  202. box-shadow: 0px 0px 10px 2px rgb(0, 0, 0, 0.3);
  203. border-radius: 4px;
  204. background: #f4f7ff;
  205. outline: 1px solid rgba(245, 248, 255, 0.25);
  206. z-index: 999;
  207. .leader-team__operation-item {
  208. height: 31.5px;
  209. line-height: 31.5px;
  210. border-radius: 4px;
  211. &:hover {
  212. color: #fff;
  213. background-color: #1777ff;
  214. cursor: pointer;
  215. }
  216. }
  217. }
  218. .adjust-menu-position {
  219. bottom: -33px;
  220. }
  221. }
  222. // 隐藏最后一个层级队伍的箭头icon
  223. .hide-arrow {
  224. .leader-team__team-name {
  225. padding-left: 22px;
  226. }
  227. :deep(.el-collapse-item button) {
  228. padding-left: 0;
  229. cursor: auto;
  230. }
  231. :deep(.el-collapse-item__arrow) {
  232. display: none;
  233. }
  234. }
  235. :deep(.el-collapse-item__header) {
  236. height: 40px;
  237. }
  238. // 防止最后一个队伍的操作面板不显示
  239. :deep(.el-collapse-item__wrap) {
  240. overflow: visible;
  241. }
  242. // 非选中队伍的名字的hover样式
  243. .leader-team__title:not(.leader-team--selected):hover {
  244. background-color: #cdd8ff;
  245. }
  246. // 非选中队伍的icon的hover样式
  247. :deep(.el-collapse-item__header:not(.el-collapse-item__header:has(.leader-team--selected)):hover) {
  248. border-radius: 4px;
  249. background-color: #cdd8ff;
  250. }
  251. // 选中队伍的hover样式
  252. :deep(.el-collapse-item__header:has(.leader-team--selected)) {
  253. background-color: #1777ff;
  254. border-radius: 4px;
  255. .leader-team__team-name,
  256. svg {
  257. color: #fff;
  258. }
  259. }
  260. }
  261. .leader-team--indent {
  262. margin-left: v-bind(indentation);
  263. }
  264. </style>