my-ranklist.vue 7.0 KB

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