my-ranklist.vue 8.4 KB

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