You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.8 KiB
89 lines
2.8 KiB
import dataDemo from './dataDemo';
|
|
|
|
|
|
|
|
/**
|
|
* xml经过doT.js编译出的模板函数
|
|
* 因为小游戏不支持new Function,模板函数只能外部编译
|
|
* 可直接拷贝本函数到小游戏中使用
|
|
*/
|
|
function tplFunc(it) {
|
|
const parts = [];
|
|
const data = it.data || [];
|
|
const dataLength = data.length;
|
|
|
|
// 预定义基础结构
|
|
parts.push('<view class="container" id="main"><view class="rankList"><scrollview id="list" class="list" scrollY="true">');
|
|
|
|
// 预定义模板路径
|
|
const bgTemplates = [
|
|
'openDataContext/image/bg_horizontal_0.png',
|
|
];
|
|
|
|
const medalTemplates = [
|
|
'openDataContext/image/rank_Num_1.png',
|
|
'openDataContext/image/rank_Num_2.png',
|
|
'openDataContext/image/rank_Num_3.png',
|
|
'openDataContext/image/rank_Num_4.png'
|
|
];
|
|
|
|
const lineImgSrc = "openDataContext/image/line.png";
|
|
const selfmedal = "openDataContext/image/rank_Num_self.png";
|
|
|
|
// 处理排行榜数据
|
|
for (let i = 0; i < dataLength; i++) {
|
|
const item = data[i];
|
|
const rank = i + 1;
|
|
const bgIndex = i <= 2 ? i : 3;
|
|
const medalClass = rank < 4 ? rank : 4;
|
|
|
|
parts.push(
|
|
`<image class="listItem" src="${bgTemplates[0]}">`,
|
|
'<view class="medalContainer">',
|
|
`<image class="medal${medalClass}" src="${medalTemplates[medalClass - 1]}">`,
|
|
`<text class="listItemNum${medalClass} outline${medalClass}" value="${rank}"></text>`,
|
|
'</image>',
|
|
'</view>',
|
|
// '<image class="listHeadBg" src="openDataContext/image/bg_touxiangkuang_01.png">',
|
|
// `<image class="listHeadImg" src="${item.avatarUrl}"></image>`,
|
|
//'</image>',
|
|
'<view class="listItemUser">',
|
|
`<text class="listItemName" value="${item.nickname}"></text>`,
|
|
'</view>',
|
|
`<text class="listItemScore outline5" value="${item.rankDesc}"></text>`,
|
|
'</image>'
|
|
);
|
|
}
|
|
|
|
parts.push('</scrollview></view>');
|
|
|
|
// 处理自己的排名信息
|
|
if (it.selfItem) {
|
|
let imgIdx = Math.min(it.selfRankIdx >= 0 ? it.selfRankIdx + 1 : 4, 4);
|
|
const rankDisplay = it.selfRankIdx < 0 ? "未上榜" : (it.selfRankIdx + 1);
|
|
parts.push(
|
|
`<image class="line" src="${lineImgSrc}"> </image>`,
|
|
'<view class="selfItem">',
|
|
|
|
`<text class="tempText outlineself" value="我的排名:"></text>`,
|
|
'<view class="medalContainerSelf">',
|
|
`<image class="medalself" src="${selfmedal}">`,
|
|
`<text class="listItemNumSelf" value="${rankDisplay}"></text>`,
|
|
'</image>',
|
|
'</view>',
|
|
//`<text class="selfItemName" value="${it.selfItem.nickname}"></text>`,
|
|
`<text class="listItemScoreSelf outline5" value="${it.selfItem.rankDesc}"></text>`,
|
|
'</view>',
|
|
);
|
|
}
|
|
|
|
parts.push('</view>');
|
|
|
|
return parts.join('');
|
|
}
|
|
|
|
var template = {
|
|
tplFunc:tplFunc,
|
|
}
|
|
|
|
export default template;
|