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 !== 2 }"
  41. @click.stop
  42. >
  43. <div v-if="props.teamData.level !== 3" @mousedown="showAddTeamDialog()" class="leader-team__operation-item">
  44. 新建队伍
  45. </div>
  46. <div v-if="props.teamData.level !== 1" @click="handleDelete()" class="leader-team__operation-item">
  47. 删除队伍
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <div v-if="props.teamData.level <= 3">
  53. <div v-for="team in props.teamData.children" :key="team.teamId">
  54. <leaderTeam :team-data="team" :parent-id="props.teamData.teamId" @expand="emitExpandEvent" />
  55. </div>
  56. </div>
  57. </el-collapse-item>
  58. </div>
  59. <AddTeam ref="addTeamRef" @emit-team-name="handleCreate" />
  60. </template>
  61. <script setup lang="ts">
  62. import { ref, watch, nextTick } from 'vue';
  63. import { storeToRefs } from 'pinia';
  64. import AddTeam from './components/AddTeam.vue';
  65. import { LeaderTeamType } from '../type';
  66. import useTeamStore from '../store/userTeam';
  67. import { updateEmergencyTeamInfo } from '@/api/emergency-organization/teams';
  68. const props = defineProps<{
  69. teamData: LeaderTeamType;
  70. parentId: number;
  71. }>();
  72. const emit = defineEmits<{ (e: 'expand', collapseId: number) }>();
  73. const indentation = `${props.teamData.level * 10}px`;
  74. const { leaderTeamTree, curTeam, loadingTeams } = storeToRefs(useTeamStore());
  75. const { getLeaderTeams, createTeam, deleteTeam, getSelectTeamInfo } = useTeamStore();
  76. const showTeamOperation = ref(false);
  77. const showRenameTeamInput = ref(false);
  78. const teamOriginName = ref(props.teamData.teamName);
  79. const inputNewTeamName = ref('');
  80. const teamNameInputRef = ref();
  81. const addTeamRef = ref<InstanceType<typeof AddTeam>>();
  82. function handleRenameTeam() {
  83. showRenameTeamInput.value = true;
  84. nextTick(() => {
  85. teamNameInputRef.value.focus();
  86. inputNewTeamName.value = teamOriginName.value;
  87. });
  88. }
  89. async function enterNewName() {
  90. if (inputNewTeamName.value === '' || inputNewTeamName.value === teamOriginName.value) {
  91. showRenameTeamInput.value = false;
  92. return;
  93. }
  94. loadingTeams.value = true;
  95. const data = { id: props.teamData.teamId, teamName: inputNewTeamName.value };
  96. await updateEmergencyTeamInfo(data);
  97. await getLeaderTeams();
  98. teamOriginName.value = inputNewTeamName.value;
  99. showRenameTeamInput.value = false;
  100. loadingTeams.value = false;
  101. }
  102. function showAddTeamDialog() {
  103. addTeamRef.value?.dialogShow();
  104. }
  105. function handleCreate(teamName: string) {
  106. createTeam(props.teamData, teamName);
  107. // 添加完成后展开队伍
  108. emitExpandEvent(props.teamData.teamId);
  109. }
  110. function handleDelete() {
  111. deleteTeam(props.teamData);
  112. }
  113. let clickTimeout: any = null;
  114. function clickTeam(event) {
  115. // 单击事件
  116. if (event.detail === 1) {
  117. clickTimeout = setTimeout(() => {
  118. if (props.teamData.teamId === leaderTeamTree.value.teamId) return;
  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. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. color: #333333;
  156. border-radius: 4px;
  157. position: relative;
  158. cursor: default;
  159. .leader-team__rename {
  160. height: 32px;
  161. width: 100%;
  162. display: flex;
  163. align-items: center;
  164. background-color: #1777ff;
  165. border-radius: 4px;
  166. font-size: 14px;
  167. line-height: 24px;
  168. padding-right: 6px;
  169. .leader-team__rename-input {
  170. height: 24px;
  171. }
  172. }
  173. .leader-team__team-name {
  174. white-space: nowrap;
  175. }
  176. .leader-team__menu-icon {
  177. visibility: hidden;
  178. margin-left: 10px;
  179. margin-right: 10px;
  180. img {
  181. height: 20px;
  182. width: 20px;
  183. &:hover {
  184. background-color: rgba(255, 255, 255, 0.2);
  185. border-radius: 4px;
  186. cursor: pointer;
  187. }
  188. }
  189. }
  190. &:hover .leader-team__menu-icon {
  191. visibility: visible;
  192. display: flex;
  193. align-items: center;
  194. }
  195. .leader-team__operation {
  196. display: block;
  197. width: 130px;
  198. position: absolute;
  199. bottom: -63px;
  200. right: 5px;
  201. box-shadow: 0px 0px 10px 2px rgb(0, 0, 0, 0.3);
  202. border-radius: 4px;
  203. background: #f4f7ff;
  204. outline: 1px solid rgba(245, 248, 255, 0.25);
  205. z-index: 9991;
  206. .leader-team__operation-item {
  207. height: 31.5px;
  208. line-height: 31.5px;
  209. border-radius: 4px;
  210. &:hover {
  211. color: #fff;
  212. background-color: #1777ff;
  213. cursor: pointer;
  214. }
  215. }
  216. }
  217. .adjust-menu-position {
  218. bottom: -33px;
  219. }
  220. }
  221. // 隐藏最后一个层级队伍的箭头icon
  222. .hide-arrow {
  223. .leader-team__team-name {
  224. padding-left: 22px;
  225. }
  226. :deep(.el-collapse-item button) {
  227. padding-left: 0;
  228. cursor: auto;
  229. }
  230. :deep(.el-collapse-item__arrow) {
  231. display: none;
  232. }
  233. }
  234. :deep(.el-collapse-item__header) {
  235. height: 40px;
  236. }
  237. // 防止最后一个队伍的操作面板不显示
  238. :deep(.el-collapse-item__wrap) {
  239. overflow: visible;
  240. }
  241. // 非选中队伍的名字的hover样式
  242. .leader-team__title:not(.leader-team--selected):hover {
  243. background-color: #cdd8ff;
  244. }
  245. // 非选中队伍的icon的hover样式
  246. :deep(.el-collapse-item__header:not(.el-collapse-item__header:has(.leader-team--selected)):hover) {
  247. border-radius: 4px;
  248. background-color: #cdd8ff;
  249. }
  250. // 选中队伍的hover样式
  251. :deep(.el-collapse-item__header:has(.leader-team--selected)) {
  252. background-color: #1777ff;
  253. border-radius: 4px;
  254. .leader-team__team-name,
  255. svg {
  256. color: #fff;
  257. }
  258. }
  259. }
  260. .leader-team--indent {
  261. margin-left: v-bind(indentation);
  262. }
  263. </style>