Commit 9f91ef5a authored by liujiangnan's avatar liujiangnan

feat

parent fbecb073
...@@ -9,7 +9,6 @@ new Vue({ ...@@ -9,7 +9,6 @@ new Vue({
//数据加载完,才算页面加载完成 //数据加载完,才算页面加载完成
//获取数据 //获取数据
this.loadRows(checkedArr||[]); this.loadRows(checkedArr||[]);
this.loadFaf(checkedArr||[]);
},key); },key);
}, },
data() { data() {
......
body { body {
background: #fff; background: #fff;
} }
#test{ .play-data {
margin: 80px; width: 100%;
height: 100%;
background: #fff;
padding: 20px;
box-sizing: border-box;
}
/* 新增: 为面包屑添加下边距 */
.el-breadcrumb {
margin-bottom: 20px;
}
.card-list {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: flex-start;
}
.card-item {
width: 200px;
cursor: pointer;
transition: all 0.3s ease;
}
.card-item:hover {
transform: translateY(-5px);
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.card-item.parent-card .card-content {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.parent-text {
font-weight: bold;
text-align: center;
/* 移除了指定的字体大小,使用默认大小 */
}
.card-item.word-card {
height: 200px;
display: flex;
justify-content: center;
align-items: center;
padding: 15px;
box-sizing: border-box;
position: relative;
}
.word-card-content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
text-align: center;
}
.audio-icon {
position: absolute;
top: 10px;
right: 10px;
font-size: 24px; /* 增大字体大小 */
color: #409EFF;
cursor: pointer;
transition: all 0.3s ease;
z-index: 1;
font-weight: bold; /* 加粗图标 */
text-shadow: 1px 1px 2px rgba(0,0,0,0.1); /* 添加轻微阴影以增加可见度 */
}
.audio-icon:hover {
transform: scale(1.2); /* 稍微增大悬停时的缩放效果 */
color: #66b1ff; /* 悬停时变亮 */
}
.word-card-content .text-en {
font-size: 28px;
font-weight: bold;
margin-bottom: 10px;
line-height: 1.2;
}
.word-card-content .phonetic {
font-size: 16px;
color: #999;
margin-bottom: 10px;
font-style: italic;
}
.word-card-content .text-cn {
font-size: 18px;
line-height: 1.4;
}
.el-breadcrumb-item.is-last {
cursor: default;
color: #606266;
}
.el-breadcrumb-item:not(.is-last) {
cursor: pointer;
}
.el-breadcrumb-item:not(.is-last):hover {
color: #409EFF;
}
.card-item.parent-card .card-content .parent-text {
font-weight: bold;
text-align: center;
font-size: 16px; /* 或者您想要的其他大小 */
}
.fullscreen-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.enlarged-card {
width: 40%;
aspect-ratio: 1 / 1;
background-color: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.enlarged-card .audio-icon {
position: absolute;
top: 10px;
right: 10px;
}
.enlarged-card .text-en {
font-size: 36px;
font-weight: bold;
margin-bottom: 15px;
}
.enlarged-card .phonetic {
font-size: 24px;
color: #999;
margin-bottom: 15px;
font-style: italic;
}
.enlarged-card .text-cn {
font-size: 28px;
}
.control-switches {
position: fixed;
left: 20px;
bottom: 20px;
display: flex;
flex-direction: column;
gap: 10px;
z-index: 1000;
}
.el-switch {
background-color: rgba(255, 255, 255, 0.8);
padding: 5px;
border-radius: 20px;
}
.el-switch__label {
color: #fff;
font-weight: bold;
}
.el-switch__label * {
font-size: 14px;
}
/* 根据开关状态控制文本显示 */
.word-card-content .text-en {
display: v-bind(showEnglish ? 'block' : 'none');
}
.word-card-content .text-cn {
display: v-bind(showChinese ? 'block' : 'none');
}
/* 同样适用于放大的卡片 */
.enlarged-card .text-en {
display: v-bind(showEnglish ? 'block' : 'none');
}
.enlarged-card .text-cn {
display: v-bind(showChinese ? 'block' : 'none');
} }
...@@ -8,9 +8,78 @@ ...@@ -8,9 +8,78 @@
<script type="text/javascript" src="../lib/js/jquery-1.12.3.min.js"></script> <script type="text/javascript" src="../lib/js/jquery-1.12.3.min.js"></script>
<link href="./index.css" rel="stylesheet" > <link href="./index.css" rel="stylesheet" >
<script type="text/javascript" src="//staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script> <script type="text/javascript" src="//staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script>
<script type="text/javascript" src="../lib/js/vue.min.js"></script>
<!-- 引入样式 -->
<link href="../lib/element-ui/theme-chalk/index.css" rel="stylesheet">
<!-- 引入组件库 -->
<script src="../lib/element-ui/index.js"></script>
</head> </head>
<body> <body>
<h1 id="test"></h1> <div class="play-data">
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item @click.native="jumpToBreadcrumb(-1)">Home</el-breadcrumb-item>
<el-breadcrumb-item
v-for="(item, index) in breadcrumb"
:key="index"
@click.native="index < breadcrumb.length - 1 && jumpToBreadcrumb(index)"
:class="{ 'is-last': index == breadcrumb.length - 1 }"
>
{{ item.text_en }}
</el-breadcrumb-item>
</el-breadcrumb>
<div class="card-list">
<el-card
v-for="item in currentRows"
:key="item.id"
class="card-item"
@click.native="loadChildren(item)"
@dblclick.native="showEnlargedCard(item)"
:class="{ 'parent-card': !item.text_cn, 'word-card': item.text_cn }"
>
<template v-if="!item.text_cn">
<div class="card-content parent-text">{{ item.text_en }}</div>
</template>
<template v-else>
<div class="word-card-content">
<i v-if="item.audio_url" class="el-icon-headset audio-icon" @click.stop="playAudio(item.audio_url)"></i>
<div class="text-en">{{ item.text_en }}</div>
<div v-if="item.phonetic" class="phonetic">{{ item.phonetic }}</div>
<div class="text-cn">{{ item.text_cn }}</div>
</div>
</template>
</el-card>
</div>
<!-- 添加全屏遮罩和放大的卡片 -->
<div v-if="enlargedCard" class="fullscreen-overlay" @click="hideEnlargedCard">
<div class="enlarged-card" @click.stop>
<i v-if="enlargedCard.audio_url" class="el-icon-headset audio-icon" @click="playAudio(enlargedCard.audio_url)"></i>
<div class="text-en">{{ enlargedCard.text_en }}</div>
<div v-if="enlargedCard.phonetic" class="phonetic">{{ enlargedCard.phonetic }}</div>
<div class="text-cn">{{ enlargedCard.text_cn }}</div>
</div>
</div>
<!-- 控制开关 -->
<div v-if="hasWordCards" class="control-switches">
<el-switch
v-model="showEnglish"
active-color="#13ce66"
inactive-color="#ff4949">
<span slot="active-text">EN</span>
<span slot="inactive-text">EN</span>
</el-switch>
<el-switch
v-model="showChinese"
active-color="#13ce66"
inactive-color="#ff4949">
<span slot="active-text">中</span>
<span slot="inactive-text">中</span>
</el-switch>
</div>
</div>
</body> </body>
<script src="./index.js"></script> <script src="./index.js"></script>
</html> </html>
// 对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱
var key = "word_tree_config";
/* new Vue({
el: '.play-data',
window.courseware.getData(callback,key); //用于获取数据 created() {
window.courseware.getData((checkedArr) => {
window.air.hideAirClassLoading(key,data); //页面加载完成时,必须调用此方法,用于隐藏遮罩层 this.checkedArr = checkedArr||[];
this.loadRows();
*/
//对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱
var key = "h5_test";
$(function(){
window.courseware.getData(function(data){
//数据加载完,才算页面加载完成
//获取数据
if(data&&data.test){
$("#test").html("Hello "+data.test);
} else{
//一般来讲,如果没有获取到数据的话,给一组默认数据,用于演示模板的展示效果,方便别人了解这个模板
$("#test").html("Hello 我是演示信息!");
}
//数据渲染完成后,添加各种交互或者动画效果
//我这里简单做一个渐入渐出效果的例子
var flag = true;
setInterval(function(){
if(flag){
$("#test").fadeIn(500);
}else{
$("#test").fadeOut(500);
}
flag = !flag;
},1000)
//在页面加载、事件、动画等都初始化完成后,一定要记得调用此方法,否则模板将是不可用的
window.air.hideAirClassLoading(key,data);
},key); },key);
},
}) data() {
\ No newline at end of file return {
rows: [],
checkedArr: [],
breadcrumb: [],
currentRows: [],
enlargedCard: null,
showEnglish: true,
showChinese: true,
hasWordCards: false, // 添加这个属性
}
},
computed: {
hasWordCards() {
return this.currentRows.some(item => item.text_cn);
}
},
methods: {
loadRows() {
$.ajax({
type: "GET",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
url: `${this.compDomain}api/dige/non/v1/gradetree/list`,
success: (xhr) => {
this.rows = xhr.rows.filter(item => this.checkedArr.includes(item.id));
this.currentRows = this.rows;
},
error: (xhr, e) => {
console.error('加载数据失败', e);
}
});
},
loadChildren(item) {
if (item.has_child === 0) {
return; // 如果没有子节点,则不进行操作
}
$.ajax({
type: "GET",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
url: `${this.compDomain}api/dige/non/v1/gradetree/list?pid=${item.id}`,
dataType: 'json', // 明确指定期望的数据类型
success: (response) => {
// 检查响应是否包含预期的数据
if (response && response.rows) {
this.currentRows = response.rows;
// 检查是否有单词卡并更新 hasWordCards
this.hasWordCards = this.currentRows.some(item => item.text_cn);
// 添加当前项到面包屑
if (!this.breadcrumb.find(breadcrumbItem => breadcrumbItem.id === item.id)) {
this.breadcrumb.push(item);
}
} else {
console.error('Unexpected response format:', response);
// 可以在这里添加错误处理,比如显示一个错误消息给用户
}
},
error: (xhr, status, error) => {
console.error('加载子节点失败', status, error);
// 可以在这里添加错误处理,比如显示一个错误消息给用户
}
});
},
jumpToBreadcrumb(index) {
if (index === -1) {
// 点击"首页"
this.currentRows = this.rows;
this.breadcrumb = [];
} else {
// 点击其他层级
const item = this.breadcrumb[index];
this.loadChildren(item);
// 移除点击层级后面的所有层
this.breadcrumb = this.breadcrumb.slice(0, index + 1);
}
},
showEnlargedCard(item) {
this.enlargedCard = item;
},
hideEnlargedCard() {
this.enlargedCard = null;
},
playAudio(audioUrl) {
if (audioUrl) {
const audio = new Audio(audioUrl);
audio.play().catch(error => {
console.error('音频播放失败:', error);
});
}
}
},
computed: {
compDomain: function () {
const protocolStr = document.location.protocol;
if (document.domain.indexOf("staging") < 0 && document.domain != 'localhost') {
return `${protocolStr}//openapi.iteachabc.com/`;
}
return `${protocolStr}//staging-openapi.iteachabc.com/`;
},
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment