my-ranklist.vue 9.8 KB

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