my-ranklist.vue 9.4 KB

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