LeaderTeam.vue 8.2 KB

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