my-ranklist.vue 8.7 KB

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