research_ui/components/research/components/ResearchContent.vue
2025-02-04 16:10:58 +03:30

844 lines
23 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="">
<div class="pt-1">
<div class="search-items firefox-scrollbar">
<div
class="search-items__item"
v-for="(item, i) in listAnswer"
:key="i"
>
<div>
<div class="search-items__header">
<a class="search-items__label text__13 text__dark-gray">{{
item._source.research_type
}}</a>
<a
class="search-items__title text__15 text__blue"
@click.prevent="showModalResearch(item, true)"
@auxclick.prevent.stop="showModalResearch(item, true)"
v-html="
highlightKey(item, 'title', 'text_subject', 'text_user')
"
>
</a>
</div>
<div>
<span style="margin-left: 10px"
>نشانی :
<a
class="search-items__title text__15 text__blue"
@click.prevent="
showtext(item._source, listAnswer, i, item._id)
"
@auxclick.prevent.stop="
showtext(item._source, listAnswer, i, item._id)
"
>
{{ item._source.address ?? "--" }}
</a>
</span>
</div>
<div class="text__15 text__dark-gray search-items__code">
<span style="margin-left: 10px"
>نوع برداشت : {{ item._source.take_type ?? "--" }}</span
>
<span style="margin-left: 10px"
>فعل متن : {{ item._source.text_verb ?? "--" }}</span
>
<span style="margin-left: 10px"
>تاریخ : {{ datefa(item._source.date_create * 1000) }}</span
>
</div>
<div class="search-items__content">
<div
class="text__15 line-clamp__2"
v-html="highlightKey(item, 'text_main')"
></div>
<div
v-if="
item._source?.subject?.length && $route.name == 'TermPage'
"
class="mt-2 text__15 text__dark-gray search-items__code"
>
<span style="margin-left: 10px">اصطلاحات :</span>
<ul>
<li
v-for="(sub, subIndex) in item._source.subject"
:key="subIndex"
>
{{ sub.title }}
</li>
</ul>
</div>
</div>
<div class="search-item__actions">
<span class="tavasi tavasi-more-vert"></span>
<!-- <button
v-can="'search_summary'"
@click.pevent="AddToFavorites(item, i)"
title="علاقه مندی ها"
class="btn show-detail-btn favorites"
type="button"
>
<svg
class="icon"
:class="
item._source.tbookmark == 1
? 'icon-bookmark-1'
: 'icon-bookmark-4'
"
>
<use
:xlink:href="
item._source.tbookmark == 1
? '#icon-bookmark-1'
: '#icon-bookmark-4'
"
></use>
</svg>
</button> -->
<!-- <button
v-can="'search_analyze'"
@click="showDetails(item)"
title="نمایش جزییات"
class="btn show-detail-btn"
type="button"
>
<span class="tavasi tavasi-eye"></span>
</button> -->
<!-- v-can="$route.name + '_subject'" برای موضوع زنی -->
<button
@click="SubjectFormHandler(item)"
title="موضوع زنی"
class="btn show-detail-btn px-1"
type="button"
>
<span class="tavasi tavasi-doc-outline"></span>
</button>
<button
v-can="'search_summary'"
@click="showModalResearch(item, false)"
title="ویرایش"
class="btn show-detail-btn -rotate-180"
type="button"
>
<svg style="color: #adbec4" class="icon icon-Component-242--1">
<use xlink:href="#icon-Component-242--1"></use>
</svg>
</button>
<button
v-can="'search_summary'"
@click="deleteResearch(item)"
title="حذف"
class="btn show-detail-btn -rotate-180"
type="button"
>
<svg style="color: #adbec4" class="icon icon-Component-295--1">
<use xlink:href="#icon-Component-295--1"></use>
</svg>
</button>
<button-component
:title="copyButtonTitleMaker(item._source)"
buttonText=""
class="btn show-detail-btn px-1"
@click="
copyToClipboard(
'',
urlResolver(item._source, item, 'entityResearch')
)
"
>
<svg class="icon icon-copy2 fz-8">
<use xlink:href="#icon-copy2"></use>
</svg>
</button-component>
</div>
</div>
</div>
</div>
<jahat-pagination
class="pagination"
style="font-size: 13px"
v-if="page.total"
:paginationInfo="page"
@page-changed="pageChanged"
@page-limit-changed="pageLimitChanged"
@sort-changed="sortChanged"
>
</jahat-pagination>
</div>
<base-modal
v-if="openSubjectForm"
modalSize="modal-lg"
:modalTitle="modalTitle"
:hasFooter="false"
@close="hideSubjectForm"
>
<component :is="slotComponentName"></component>
</base-modal>
</div>
</template>
<script>
import favoriteApi from "~/apis/favoriteApi";
import researchApi from "~/apis/researchApi";
import { mapState, mapActions } from "pinia";
import { useResearchStore } from "~/stores/researchStore";
export default {
props: {
summeryKeys: {
default() {
return {};
},
},
listAnswer: {
type: Array,
default: () => [],
},
pagination: {
default() {
return {};
},
},
listSelectedPoint: {
default() {
return [];
},
},
},
beforeMount() {
this.httpService = new HttpService(import.meta.env.VITE_REPO_BASE_URL);
},
mounted() {
window.scrollTo(0, 0);
if (this.$route.query.q) this.searchText = this.$route.query.q;
if (this.myActiveSchema) {
this.researchActiveSchemaSetter(this.myActiveSchema);
}
// if (this.listAnswer.length>=0) {
// console.log(this.selectedlists)
// this.listAnswer=this.selectedlists
// }
},
watch: {
// selectedlists(newVal) {
// if (this.listAnswer.length>=0) {
// console.log(this.selectedlists)
// this.listAnswer=this.selectedlists
// }
// },
pagination(newVal) {
this.page = newVal;
},
listSelectedPoint(newVal) {
this.listAnswer = newVal;
},
},
data() {
return {
openSubjectForm: false,
slotComponentName: "",
modalTitle: "",
showModal: false,
listId: undefined,
projectId: undefined,
selectedItem: undefined,
page: this.pagination,
// listAnswer: [],
totalCount: 0,
typeCount: "",
countInPage: 0,
maxPage: 0,
currentPage: 1,
beginPage: 1,
endPage: 1,
listPage: [],
textSearch: "",
iscode: true,
maxLength: 250,
httpService: undefined,
navigationOptions: [],
sorting: {
sortby: "created",
sortorder: undefined, // asc | desc | none
},
};
},
computed: {
...mapState(["userPermisionGetter", "currentUser", "selectedlists"]),
...mapState(useResearchStore, ["researchSchemaGetter"]),
...mapState(useSearchStore, ["searchActiveTabGetter"]),
showActionMenu() {
let show = false;
if (this.userPermisionGetter?.length)
["search_analyze", "search_summary"].forEach(
(item) =>
(show =
this.currentUser.user_level > 1 ||
this.userPermisionGetter.includes(item))
);
return show;
},
myActiveSchema() {
return this.researchSchemaGetter?.find((item) => {
return item.key == "research";
});
},
},
methods: {
...mapActions("list", ["SET_SELECTED_ITEM", "SET_LIST"]),
...mapActions(useResearchStore, ["researchActiveSchemaSetter"]),
...mapActions("entity", ["SET_ITEM_ENTITY", "SET_LIST_ENTITY"]),
showModalResearch(item, isReadonly) {
let schema = this.myActiveSchema.contextMenu.find(
(itemKey) => itemKey.key === item._source?.research_key
);
this.$emit("researchModalHandler", {
action: "edit",
itemEdit: item,
itemSchema: schema,
isReadonly: isReadonly,
});
},
deleteResearch(item) {
mySwalConfirm({
title: "هشدار!!!",
html: `از حذف <b>${item._source.text_subject}</b> اطمینان دارید؟ `,
icon: "warning",
}).then((result) => {
if (result.isConfirmed) {
let url = researchApi.research.deleteItem;
url = url.replace("{{index_key}}", item._source.ref_key);
url = url.replace("{{id}}", item._id);
this.httpService.postRequest(url).then((res) => {
mySwalToast({
html: res.message,
});
setTimeout(() => {
this.$emit("updateForDeleteResearch");
}, 500);
});
}
});
},
SubjectFormHandler(item) {
this.openModalFilter("SubjectForm", "موضوع زنی");
let cloneItem = structuredClone(item);
cloneItem = { ...item._source, _id: item._id };
this.SET_SELECTED_ITEM(cloneItem);
},
openModalFilter(componentName, title) {
this.openSubjectForm = true;
this.slotComponentName = componentName;
this.modalTitle = title;
setTimeout(() => {
$("#meta-item-modal").modal(
{ backdrop: "static", keyboard: false },
"show"
);
}, 500);
},
hideSubjectForm() {
$("#base-modal").modal({
show: false,
});
setTimeout(() => {
this.openSubjectForm = false;
}, 200);
},
copyButtonTitleMaker(item) {
return `کپی لینک: link:\n${location.origin + this.urlResolver(item)}`;
},
// //This function adds a new favorite to the user's favorites
// AddToFavorites(item, index) {
// if (item._source.tbookmark == 0) {
// let url = favoriteApi.favorite.add;
// url = url.replace("{{data_type}}", "bookmark");
// url = url.replace("{{ref_key}}", this.researchSchemaGetter[0].key);
// const formData = {
// ref_id: item._id,
// title: item._source.title,
// };
// this.httpService.postRequest(url, formData).then((res) => {
// console.log(res);
// // this.UpdateList();
// //refresh After removing or adding favorites
// //this.$emit("UpdateList", item.tbookmark);
// this.updateListAnswer(index, "tbookmark", 1);
// });
// } else {
// let url = favoriteApi.favorite.delete;
// url = url.replace("{{data_type}}", "bookmark");
// url = url.replace("{{id}}", item._id);
// const formData = {
// ref_id: item._id,
// title: item._source.title,
// };
// this.httpService.postRequest(url, formData).then((res) => {
// console.log(res);
// //refresh After removing or adding favorites
// //this.$emit("UpdateList", item.tbookmark);
// this.updateListAnswer(index, "tbookmark", 0);
// });
// }
// },
updateListAnswer(index, key, value) {
if (index in this.listAnswer) {
if (key in this.listAnswer[index]["_source"])
this.listAnswer[index]["_source"][key] = value;
}
},
datefa(item) {
var m = item;
var d = new Date(m).toLocaleDateString("fa-IR");
return d;
},
countAudio(item) {
return item._source.voices;
},
showDetails(selectedItem) {
this.selectedItem = selectedItem;
this.openModal();
},
closeModal() {
$("#subject-modal")?.modal("hide");
setTimeout(() => {
this.showModal = false;
}, 500);
},
openModal() {
this.showModal = true;
setTimeout(() => {
$("#subject-modal")?.modal(
{ backdrop: "static", keyboard: false },
"show"
);
}, 500);
},
highlightKey(item, key1, key2 = "", key3 = "") {
var text = "";
if (item.highlight) {
if (item.highlight[key1]) text = item.highlight[key1].join("... ");
else if (key2 && item.highlight[key2])
text = item.highlight[key2].join("... ");
else if (key3 && item.highlight[key3])
text = item.highlight[key3].join("... ");
}
if (text == "") {
if (item._source[key1]) text = item._source[key1];
else if (key2 && item._source[key2]) text = item._source[key2];
else if (key3 && item._source[key3]) text = item._source[key3];
if (text.length > 500) text = text.substring(0, 500);
}
return text;
},
/*
اگر تب انتخاب شده همه باشد،کلید ها content خواهد بود.
اگر تب انتخاب شده فهرست باشد،کلید ها mindex & mintro خواهد بود.
*/
// urlResolver(_id) {
// if (this.researchSchemaGetter) {
// const routeData = this.$router.resolve({
// name: "navigationView",
// params: {
// id: _id,
// key: this.researchSchemaGetter[0].key,
// },
// query: {},
// });
// return routeData.href;
// }
// },
urlResolver(_source, item, _name = "research") {
const routeData = this.$router.resolve({
name: _name,
params: {
id: _source.ref_id,
key: "sanad",
},
query: {
research_id: item?._id ?? undefined,
research_type: _source?.research_type ?? undefined,
},
});
return routeData.href;
},
showMultiText(id, _listkey) {
let _name = "navigation";
const routeData = this.$router.resolve({
name: _name,
params: {
id: id,
key: this.researchSchemaGetter[0].key,
},
query: {
searchtext: this.textSearch ?? undefined,
listkey: _listkey,
},
});
window.open(routeData.href, "_blank");
},
showtext(item, listAnswer, i, _id) {
let cloneList = structuredClone(listAnswer);
cloneList.forEach((item, index) => {
cloneList[index] = { ...item, ...item._source };
});
let cloneItem = structuredClone(item);
cloneItem = { ...item, _id: _id };
// this.SET_ITEM_ENTITY(cloneItem);
// this.SET_LIST_ENTITY(cloneList);
// localStorage.setItem("myList", JSON.stringify(cloneList));
// localStorage.setItem("myItem", JSON.stringify(cloneItem));
const domainName = buildName() + "";
let _name = "entityResearch";
const routeData = this.$router.resolve({
name: _name,
params: {
id: cloneItem.ref_id,
// key: cloneItem.ref_key,
key: "sanad",
},
query: {
research_id: cloneItem._id ?? undefined,
research_type: cloneItem.research_type ?? undefined,
},
});
window.open(routeData.href, "_blank");
},
setAnswer: function (list, count = -1, _typeCount = "") {
if (count != -1) {
this.totalCount = count;
this.typeCount = _typeCount == "eq" ? "مساوی با " : "بیشتر از ";
this.maxPage =
this.totalCount == 0
? 0
: Math.floor(this.totalCount / this.countInPage) + 1;
this.currentPage = 1;
this.beginPage = 2;
this.endPage = this.beginPage + 3;
if (this.endPage > this.maxPage - 1) {
this.endPage = this.maxPage - 1;
if (this.beginPage > 2) this.beginPage = this.beginPage - 1;
}
this.updateListPage();
}
const total = count;
const pages = Math.ceil(total / this.page.limit);
const pagination = {
total: total,
pages: pages == 0 ? 1 : pages,
};
this.page = { ...this.pagination, ...pagination };
this.listAnswer = list;
this.scrollToTop();
localStorage.setItem("answer", JSON.stringify(this.listAnswer));
},
updateListPage: function () {
this.listPage = [];
for (let i = this.endPage; i >= this.beginPage; i--) {
this.listPage.push(i);
}
setTimeout(() => {
this.scrollToTop();
}, 700);
},
nextPage: function (item) {
if (item > 0) this.setPage(this.currentPage + 1);
else this.setPage(this.currentPage - 1);
},
setPage: function (item) {
if (item == -1) {
// begin ...
item = 3;
this.beginPage = 2;
this.endPage = 5;
} else if (item == -2) {
// end ...
item = this.maxPage - 3;
this.beginPage = this.maxPage - 5;
this.endPage = this.maxPage - 1;
} else if (item == this.beginPage) {
this.beginPage--;
if (this.beginPage > 5) {
this.beginPage--;
this.endPage--;
} else {
this.beginPage = 2;
this.endPage = 5;
}
} else if (item == this.endPage) {
if (this.endPage < this.maxPage - 5) {
this.endPage++;
this.beginPage++;
} else {
this.beginPage = this.maxPage - 5;
this.endPage = this.maxPage - 1;
}
}
this.updateListPage();
this.currentPage = item;
this.$emit("changePage", item - 1);
},
changeCurrent: function (i) {
this.$emit("changeCurrent", this.listAnswer[i]);
},
setTextSearch(item, countInPage) {
this.textSearch = item;
this.countInPage = countInPage;
// console.log(this.textSearch);
},
scrollToTop() {
window.scrollTo(0, 0);
},
//mehdi
pageLimitChanged(paging) {
this.resetPagination();
this.page.limit = paging.limit;
this.$emit("changePage", this.page);
},
pageChanged(paging) {
let page = paging.pageNumber;
page -= 1;
this.page.offset = page * paging.limit;
this.page.limit = paging.limit;
this.page.page = paging.pageNumber;
this.$emit("changePage", this.page);
},
sortChanged(sorting) {
this.page.page = this.page.offset = 0;
this.sorting = sorting;
this.$emit("changePage", this.sorting);
},
resetPagination() {
this.page = {
pages: 0,
total: 0,
page: 1,
offset: 0,
limit: 10,
};
},
setListAnswer() {},
// getListSpecial(_entityType, _specialType) {
// if (this.fetchingData) return;
// this.fetchingData = true;
// this.entity_type = _entityType;
// let url = searchApi.Farhanghestan.search_normal;
// url = url + `/${this.pagination.offset}/${this.pagination.limit}/`;
// this.httpService.getRequest(url).then((res) => {
// this.listEntity = res.hits.hits;
// const total = res.hits.total.value;
// const pages = Math.ceil(total / this.pagination.limit);
// const pagination = {
// total: total,
// pages: pages == 0 ? 1 : pages
// }
// this.pagination = { ...this.pagination, ...pagination };
// this.fetchingData = false;
// });
// },
getList(_entityType) {
if (this.fetchingData) return;
this.fetchingData = true;
this.entity_type = _entityType;
let url =
searchApi.Farhanghestan.search_normal +
`/${this.page.offset}/${this.page.limit}`;
this.httpService.getRequest(url).then((res) => {
this.listEntity = res.hits.hits;
const total = res.hits.total.value;
const pages = Math.ceil(total / this.page.limit);
const pagination = {
total: total,
pages: pages == 0 ? 1 : pages,
};
this.page = { ...this.pagination, ...pagination };
this.fetchingData = false;
});
},
},
};
</script>
<style lang="scss" scoped>
// .detail-page__tab-content {
// width: 90%;
// margin-right: 0 !important;
// position: relative;
// &.serve-majles {
// width: 100%;
// }
// }
// .search-items {
// overflow-y: auto;
// height: calc(100vh - 13em);
// }
.search-items__item {
position: relative;
padding: 1em;
overflow: hidden;
&:not(:last-child) {
margin-bottom: 30px;
}
&:hover,
&.active {
background-color: var(--list-background-color);
.search-item__actions {
// width: 6.5em;
width: auto;
transition: width 0.5s;
background: #fff;
border-radius: 0 0.5em 0.5em 0;
.tavasi-more-vert {
transition: all 0.2s;
display: none;
}
}
}
}
.search-item__actions {
position: absolute;
left: 0;
width: 1.6em;
top: 1em;
// overflow: hidden;
transition: all 0.5s;
display: flex;
align-items: center;
.btn {
display: flex;
align-items: center;
justify-content: center;
padding: 0.175rem 0.35rem;
&:hover {
filter: brightness(0.7);
}
.tavasi,
.icon-copy2 {
color: #adbec4;
}
.icon-copy2 {
font-size: 0.8rem;
}
&.favorites {
color: calc(--primary-color);
.icon-bookmark-1,
.icon-bookmark-4 {
height: 1.3em;
}
}
}
}
// .detail-page__content {
// top: 35px !important;
// }
// @media only screen and (min-width: 576px) and (max-width: 767.98px) {
// .detail-page__content {
// top: 170px !important;
// }
// }
// @media (max-width: 575.98px) {
// .detail-page__content {
// top: 170px !important;
// }
// }
// @media (max-width: 575.98px) {
// }
// @media only screen and (min-width: 576px) and (max-width: 767.98px) {
// .detail-page__tab-content {
// max-width: 500px;
// }
// }
// @media only screen and (min-width: 768px) and (max-width: 900.98px) {
// .detail-page__tab-content {
// max-width: 600px;
// }
// }
// @media only screen and (min-width: 901px) and (max-width: 1049.98px) {
// .detail-page__tab-content {
// max-width: 900px;
// }
// }
// @media (min-width: 1050px) {
// }
</style>