|
|
@ -16,7 +16,7 @@ |
|
|
|
<el-dropdown-menu> |
|
|
|
<el-dropdown-menu> |
|
|
|
<ul> |
|
|
|
<ul> |
|
|
|
<li class="flex-container" @click="newViews(listObject)" v-for="listObject in essay"> |
|
|
|
<li class="flex-container" @click="newViews(listObject)" v-for="listObject in essay"> |
|
|
|
<el-dropdown-item> |
|
|
|
<el-dropdown-item @click="incrementViewsAndShow(listObject)"> |
|
|
|
<el-tag type="info" size="large" style="height: 30px;font-size: 15px"> |
|
|
|
<el-tag type="info" size="large" style="height: 30px;font-size: 15px"> |
|
|
|
<p >{{listObject.title}}</p> |
|
|
|
<p >{{listObject.title}}</p> |
|
|
|
</el-tag> |
|
|
|
</el-tag> |
|
|
@ -61,6 +61,7 @@ |
|
|
|
import { |
|
|
|
import { |
|
|
|
queryCategory, |
|
|
|
queryCategory, |
|
|
|
queryEssay, |
|
|
|
queryEssay, |
|
|
|
|
|
|
|
viewsNumberAdd |
|
|
|
} from "@/api/user/news.js" |
|
|
|
} from "@/api/user/news.js" |
|
|
|
import {ref,onMounted} from 'vue'; |
|
|
|
import {ref,onMounted} from 'vue'; |
|
|
|
import {ElMessage} from 'element-plus' |
|
|
|
import {ElMessage} from 'element-plus' |
|
|
@ -88,12 +89,30 @@ onMounted(() => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
const essay = ref([]) |
|
|
|
const essay = ref([]) |
|
|
|
const nowTimeNewsData = ref({}) |
|
|
|
const nowTimeNewsData = ref({}) |
|
|
|
|
|
|
|
|
|
|
|
//新闻详细信息获取 |
|
|
|
//新闻详细信息获取 |
|
|
|
const newViews = (listObject)=> { |
|
|
|
const newViews = (listObject)=> { |
|
|
|
nowTimeNewsData.value = { ...listObject } |
|
|
|
nowTimeNewsData.value = { ...listObject } |
|
|
|
console.log(nowTimeNewsData,'当前点击新闻详细内容') |
|
|
|
console.log(nowTimeNewsData,'当前点击新闻详细内容') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 增加一个变量记录上一次请求的时间 |
|
|
|
|
|
|
|
let lastRequestTime = 0; |
|
|
|
|
|
|
|
const incrementViewsAndShow = async (listObject) => { |
|
|
|
|
|
|
|
const currentTime = Date.now(); |
|
|
|
|
|
|
|
// 检查是否在短时间内重复请求 |
|
|
|
|
|
|
|
if (currentTime - lastRequestTime < 1000) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// 调用API增加阅读量 |
|
|
|
|
|
|
|
await viewsNumberAdd(listObject.id); |
|
|
|
|
|
|
|
lastRequestTime = currentTime; // 更新最后请求的时间 |
|
|
|
|
|
|
|
nowTimeNewsData.value = { ...listObject }; |
|
|
|
|
|
|
|
console.log(nowTimeNewsData.value, '当前点击新闻详细内容'); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
ElMessage.error('增加阅读量失败,请稍后再试!'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 新闻文章查询 |
|
|
|
// 新闻文章查询 |
|
|
|
const EssayList = async (id) => { |
|
|
|
const EssayList = async (id) => { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -102,11 +121,11 @@ const EssayList = async (id) => { |
|
|
|
const filteredEssays = response.data.filter((item) => item.status === 1); |
|
|
|
const filteredEssays = response.data.filter((item) => item.status === 1); |
|
|
|
essay.value = filteredEssays; |
|
|
|
essay.value = filteredEssays; |
|
|
|
// 如果过滤后的列表有内容,则显示第一条新闻 |
|
|
|
// 如果过滤后的列表有内容,则显示第一条新闻 |
|
|
|
if (essay.value.length > 0) { |
|
|
|
// if (essay.value.length > 0) { |
|
|
|
newViews(essay.value[0]); // 显示第一条新闻 |
|
|
|
// newViews(essay.value[0]); // 显示第一条新闻 |
|
|
|
} else { |
|
|
|
// } else { |
|
|
|
ElMessage.warning('此栏目下没有可用的新闻!'); |
|
|
|
// ElMessage.warning('此栏目下没有可用的新闻!'); |
|
|
|
} |
|
|
|
// } |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
ElMessage.error('获取新闻列表失败,请稍后再试!'); |
|
|
|
ElMessage.error('获取新闻列表失败,请稍后再试!'); |
|
|
|
} |
|
|
|
} |
|
|
|