my-ranklist.vue 7.6 KB

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