my-ranklist.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <uni-list ref="list" class="list" :border="false" @click="test">
  3. <uni-list-item v-for="(item,index) in rankRs" :key="index" :border="false" class="list-item uni-row"
  4. :class="getListItemClass(item,index)">
  5. <template v-slot:body>
  6. <text class="item-rankNum"
  7. :class="getMedalClass(item.rankNum)">{{item.rankNum > 0 ? item.rankNum : '--'}}</text>
  8. <view class="item-detail uni-row">
  9. <text
  10. class="item-userName">{{ teamType >= 0 ? getTeamName(teamType, item.userName) : item.userName}}</text>
  11. <text class="item-totalTime">{{fmtTime(item.totalTime)}}</text>
  12. </view>
  13. </template>
  14. </uni-list-item>
  15. </uni-list>
  16. </template>
  17. <script>
  18. import tools from '/common/tools';
  19. import {
  20. teamName
  21. } from '/common/define';
  22. export default {
  23. name: "my-ranklist",
  24. props: {
  25. rankRs: {},
  26. teamType: {
  27. type: Number,
  28. default: -1
  29. },
  30. myOldRankNum: { // 我的旧排名
  31. type: Number,
  32. default: null
  33. },
  34. myNewRankNum: { // 我的新排名
  35. type: Number,
  36. default: null
  37. }
  38. },
  39. data() {
  40. return {
  41. curMoveIndex: null, // 当前正在移动的列表Index (等于 rankNum-1) 用于排名变动的动画效果
  42. refList: null,
  43. refListItems: null,
  44. // item: {}
  45. };
  46. },
  47. mounted() {
  48. this.refList = this.$refs.list;
  49. this.refListItems = this.refList.$el.children;
  50. // console.log("refListItems", this.refListItems);
  51. },
  52. methods: {
  53. getListItemClass(item, index) {
  54. // console.log("item", item);
  55. if (item == undefined) {
  56. return "";
  57. }
  58. let classStr = "";
  59. // if (item.rankNum >= 0 && this.curMoveIndex == item.rankNum-1) {
  60. if (this.curMoveIndex == index) {
  61. classStr += " list-item-move"
  62. // console.log("list-item-move curMoveIndex", this.curMoveIndex);
  63. }
  64. if (item.isSelf) {
  65. classStr += " list-item-isself"
  66. }
  67. return classStr;
  68. },
  69. getTeamName(teamType, teamIndex) {
  70. return teamName[teamType][teamIndex];
  71. },
  72. getMedalClass(rankNum) {
  73. if (rankNum == 0)
  74. return 'item-rankNum-other';
  75. if (rankNum <= 3)
  76. return 'item-rankNum-medal-' + rankNum;
  77. else if (rankNum <= 10)
  78. return 'item-rankNum-medal-other';
  79. else
  80. return 'item-rankNum-other';
  81. },
  82. fmtTime(time) {
  83. if (time > 0)
  84. return tools.convertSecondsToHMS(time, 1);
  85. else
  86. return '--';
  87. },
  88. // 排名上升
  89. moveRankUp(i, animation = false) {
  90. // console.log("moveRankUp:", i, animation, this.rankRs[i]);
  91. const temp = this.rankRs[i];
  92. this.rankRs[i] = this.rankRs[i-1];
  93. this.rankRs[i-1] = temp;
  94. this.rankRs[i-1].rankNum--;
  95. if (animation) {
  96. this.curMoveIndex = i-1;
  97. this.refListItems[i-1].scrollIntoView(true);
  98. }
  99. // console.log("rankRs:", i, rankRs);
  100. },
  101. // 排名下降
  102. moveRankDown(i, animation = false) {
  103. // console.log("moveRankDown:", i, animation, this.rankRs[i]);
  104. const temp = this.rankRs[i];
  105. this.rankRs[i] = this.rankRs[i+1];
  106. this.rankRs[i+1] = temp;
  107. this.rankRs[i+1].rankNum++;
  108. if (animation) {
  109. this.curMoveIndex = i+1;
  110. this.refListItems[i+1].scrollIntoView(false);
  111. }
  112. // console.log("rankRs:", i, rankRs);
  113. },
  114. // 更新排名
  115. moveRank(myOldRankNum, myNewRankNum, animation = false) {
  116. if (!(myOldRankNum > 0)) {
  117. console.log("[moveRank] 我的旧排名为空,终止执行", myOldRankNum);
  118. return;
  119. }
  120. if (!(myNewRankNum > 0)) {
  121. console.log("[moveRank] 我的新排名为空,终止执行", myNewRankNum);
  122. return;
  123. }
  124. const difNum = myOldRankNum - myNewRankNum;
  125. if (difNum > 0) { // 排名上升
  126. // console.log("排名上升");
  127. let t = 1;
  128. for (var i = myOldRankNum - 1; i > myNewRankNum - 1; i--) {
  129. if (animation) {
  130. setTimeout(this.moveRankUp, 200 * t, i, animation);
  131. } else {
  132. this.moveRankUp(i, animation);
  133. }
  134. t++;
  135. }
  136. } else if (difNum < 0) { // 排名下降
  137. // console.log("排名下降");
  138. let t = 1;
  139. for (var i = myOldRankNum - 1; i < myNewRankNum - 1; i++) {
  140. if (animation) {
  141. setTimeout(this.moveRankDown, 200 * t, i, animation);
  142. } else {
  143. this.moveRankDown(i, animation);
  144. }
  145. t++;
  146. }
  147. }
  148. },
  149. test() {
  150. return;
  151. // const oldRankNum = 1;
  152. // const newRankNum = 20;
  153. const oldRankNum = 20;
  154. const newRankNum = 10;
  155. // 先将我的排名恢复到旧排名
  156. this.moveRank(newRankNum, oldRankNum);
  157. // 再将我的旧排名已动画的形式更新到新排名
  158. setTimeout(this.moveRank, 3000, oldRankNum, newRankNum, true);
  159. // this.moveRank(oldRankNum, newRankNum, true);
  160. }
  161. // onItemClick(item) {
  162. // this.data.item = item
  163. // this.$emit('my-combo-list-click', this.data);
  164. // }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .list {
  170. width: 90%;
  171. height: 53vh;
  172. /* margin-top: 20rpx; */
  173. /* margin-top: 1vh; */
  174. overflow: scroll;
  175. }
  176. .list-item {
  177. width: 100%;
  178. height: 70rpx;
  179. justify-content: flex-start;
  180. // transition: all 1s ease;
  181. // -webkit-transition: all 1s ease;
  182. }
  183. .list-item-move {
  184. background-color: #bd640a !important;
  185. }
  186. .list-item-isself {
  187. background-color: #ececea !important;
  188. border-radius: 10rpx;
  189. }
  190. .item-rankNum {
  191. width: 80rpx;
  192. height: 50rpx;
  193. text-align: center;
  194. margin-top: 6rpx;
  195. padding-right: 0.5rpx;
  196. margin-right: 20rpx;
  197. font-size: 26rpx;
  198. font-weight: bold;
  199. line-height: 50rpx;
  200. background-repeat: no-repeat;
  201. background-position-x: center;
  202. background-position-y: top;
  203. background-size: contain;
  204. }
  205. .item-detail {
  206. width: 82%;
  207. height: 60rpx;
  208. padding-left: 10rpx;
  209. padding-right: 10rpx;
  210. border-bottom: #ececea 5rpx solid;
  211. justify-content: space-between;
  212. }
  213. .item-rankNum-medal-1 {
  214. color: #bd640a;
  215. background-image: url("/static/default/medal_gold.png");
  216. }
  217. .item-rankNum-medal-2 {
  218. color: #68758c;
  219. background-image: url("/static/default/medal_silver.png");
  220. }
  221. .item-rankNum-medal-3 {
  222. color: #9b3b11;
  223. background-image: url("/static/default/medal_copper.png");
  224. }
  225. .item-rankNum-medal-other {
  226. color: #9a140a;
  227. background-image: url("/static/default/medal_other.png");
  228. }
  229. .item-rankNum-other {
  230. color: #9a140a;
  231. }
  232. .item-userName {
  233. font-size: 30rpx;
  234. }
  235. .item-totalTime {
  236. font-size: 26rpx;
  237. font-weight: 550;
  238. }
  239. </style>