t_L_lab_detail.js 1.99 KB

// 字符上标
function convertToSuperscript(str) {
    var regex = /[\\\\|\?]+/; // 定义特殊符号的正则表达式

    if (regex.test(str)) {
        return str.replace(/([\\\\|\?])/g, '<sup>$1</sup>'); // 使用正则表达式全局替换特殊符号并添加上标样式
    } else {
        return str;
    }
}

//获取url传来的值
let arr = window.location.href.split('?')[1]
let id = arr.split('=')[1]
let baseUrl = 'https://ccdcfile.oss-cn-chengdu.aliyuncs.com'
console.log(arr)
let urlStr = window.location.href
let apilang = ''
let strIntroduce = ''
if(urlStr.includes('English')){
    // url = url.replace('English',change)
    // window.location.href = url
    apilang = 'English'
    strIntroduce = 'INTRODUCE'
}else if(urlStr.includes('Chinese')){
    apilang = 'Chinese'
    strIntroduce = '介绍'
}else if(urlStr.includes('Russian')){
    apilang = 'Russian'
    strIntroduce = 'Презентация'
}else if(urlStr.includes('Spain')){
    apilang = 'Spain'
    strIntroduce = 'Introducción'
}
// 根据ID获取详情
$.get(`http://www.ccdcdf.com:6080/api/index/getProductById?id=${id}&apilang=${apilang}`, function (res) {
    console.log('返回的数据', res)
    let data = res.data
    let title = convertToSuperscript(data.title)
    let description = convertToSuperscript(data.description)
    let introduce = convertToSuperscript(data.introduce)
    let arr = data.images.split(',')

    let str2 = ''
    str2 = `<div class="lab_detail_cont">
    <p class="title">${data.title}
    </p>
    <div class="team_pic">
        <img src="${arr[0]}" class="lef">
        <div class="rig">
            <img src="${arr[1]}" alt="">
            <img src="${arr[2]}" alt="">
        </div>
    </div>
    <div class="bot_swiper">
        <div class="lef">
            <p>
                ${strIntroduce}
            </p>
            <p style="height:auto;">
                ${data.content}
            </p>
        </div>
    </div>
</div>
`
    // $('.fen').append(str1)
    $('.tab-content').append(str2)

})