my-ranklist.vue 9.2 KB

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