my-ranklist.vue 8.7 KB

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