123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <template>
- <div class="tree-wrapper card-shadow">
- <el-input
- v-model="filterText"
- placeholder="输入关键字过滤"
- @input="funfilterChange"
- />
- <el-tree
- class="treeRef"
- ref="treeRef"
- :data="props.data"
- :show-checkbox="props.showCheckbox"
- default-expand-all
- node-key="id"
- highlight-current
- :props="defaultProps"
- :current-node-key="''"
- @check="funCheckChange"
- :expand-on-click-node="false"
- @node-click="funCurrentChange"
- :filter-node-method="funTreeFilter"
- >
- <template #default="{ node, data }">
- <p v-if="node.level === 1" class="dashboard-tree-title">
- <span>{{ node.label }}</span>
- <el-icon
- class="refresh"
- size="14"
- title="刷新"
- @click.stop="emits('refresh')"
- >
- <RefreshRight />
- </el-icon>
- </p>
- <el-dropdown
- ref="dropdown1"
- v-else
- size="small"
- trigger="contextmenu"
- @command="funCommand"
- style="color: #b3bdc0"
- >
- <span class="el-dropdown-link">
- <el-icon>
- <Folder
- v-if="!node.expanded || (node.isLeaf && !node.isCurrent)"
- />
- <FolderOpened v-else />
- </el-icon>
- {{ node.label }}
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item
- v-if="props.dropdownMenu.includes('save')"
- :command="{ type: 'save', data, node }"
- >保存</el-dropdown-item
- >
- <el-dropdown-item
- v-if="
- data.childs &&
- data.childs.length &&
- props.dropdownMenu.includes('export')
- "
- :command="{ type: 'export', data, node }"
- >导出
- </el-dropdown-item>
- <el-dropdown-item
- v-if="props.dropdownMenu.includes('delete')"
- :command="{ type: 'delete', data, node }"
- >删除</el-dropdown-item
- >
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </template>
- </el-tree>
- </div>
- </template>
- <script setup name="search">
- import { ref, defineExpose, defineEmits, defineProps } from "vue";
- import {
- fittingCurveSave,
- dataOptionDel,
- filesDel,
- } from "@/api/powerGenerating/index.js";
- import { ElMessage, ElMessageBox } from "element-plus";
- const baseURL = process.env.VUE_APP_TEST;
- const socketURL = process.env.WS_APP_TEST;
- const emits = defineEmits(["currentChange", "checkChange", "refresh"]);
- const props = defineProps({
- data: {
- type: Array,
- default: () => {},
- },
- showCheckbox: {
- type: Boolean,
- default: false,
- },
- type: {
- type: String,
- default: "wind",
- },
- dropdownMenu: {
- type: Array,
- default: () => ["export", "delete"],
- },
- });
- const treeRef = ref();
- const filterText = ref("");
- /**输入框过滤 */
- const funfilterChange = () => {
- treeRef.value.filter(filterText.value);
- };
- const funTreeFilter = (value, data) => {
- if (!value) return true;
- return data.label.includes(value);
- };
- /**选中节点变化 */
- const funCurrentChange = (current, currentNode) => {
- emits("currentChange", { current, currentNode });
- };
- /**复选框选中变化 */
- const funCheckChange = (
- current,
- { checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys }
- ) => {
- emits("checkChange", {
- current,
- checkedNodes,
- checkedKeys,
- halfCheckedNodes,
- halfCheckedKeys,
- });
- };
- //右键时, command菜单
- const funCommand = async ({ type, data, node }) => {
- switch (type) {
- case "save":
- /**该保存功能目前暂用于风电场, combine页 */
- if (props.type !== "wind") {
- return false;
- }
- ElMessageBox.confirm("确认保存当前节点的拟合功率?", "保存", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- type: "warning",
- }).then(async () => {
- let saveArr = [];
- const repeatArr = (arr, saveArr) => {
- for (const unit of arr) {
- if (unit.childs?.length) {
- saveArr.push(...unit.childs.map((o) => o.id));
- } else if (unit.children?.length) {
- repeatArr(unit.children, saveArr);
- }
- }
- };
- if (data.childs?.length) {
- saveArr = data.childs.map((o) => o.id);
- } else if (data.children?.length) {
- repeatArr(data.children, saveArr);
- }
- let res = { code: 500 };
- res = await fittingCurveSave({ ids: saveArr.join(",") }); //删除当前节点
- if (res.code === 200) {
- ElMessage.success(res.msg);
- }
- });
- break;
- case "export":
- ElMessageBox.confirm("确认导出当前节点的所有数据?", "导出", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- const a = document.createElement("a");
- let childs = [];
- childs =
- props.type === "wind"
- ? data.childs.map((o) => o.id)
- : data.childs.map((o) => o.path);
- const url =
- props.type === "wind"
- ? "/data/option/download?ids="
- : "/export/files?filename=";
- a.href = baseURL + url + childs.join(",");
- a.download = "";
- a.target = "_blank";
- a.click();
- });
- break;
- case "delete":
- ElMessageBox.confirm("确认删除当前节点的所有数据?", "删除", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- type: "warning",
- }).then(async () => {
- let deleteArr = [];
- const repeatArr = (arr, deleteArr) => {
- for (const unit of arr) {
- if (unit.childs?.length) {
- deleteArr.push(
- ...unit.childs.map((o) =>
- props.type === "wind" ? o.id : o.path
- )
- );
- } else if (unit.children?.length) {
- repeatArr(unit.children, deleteArr);
- }
- }
- };
- if (data.childs?.length) {
- deleteArr = data.childs.map((o) =>
- props.type === "wind" ? o.id : o.path
- );
- } else if (data.children?.length) {
- repeatArr(data.children, deleteArr);
- }
- let res = { code: 500 };
- if (props.type === "wind") {
- res = await dataOptionDel({ ids: deleteArr.join(",") }); //删除当前节点
- } else {
- res = await filesDel({ filename: deleteArr.join(",") }); //删除当前节点
- }
- if (res.code === 200) {
- ElMessage.success(res.msg);
- emits("refresh");
- }
- });
- break;
- }
- };
- const getCheckedNodes = () => {
- // // console.log(treeRef.value!.getCheckedNodes(false, false));
- };
- const getCheckedKeys = () => {
- // // console.log(treeRef.value!.getCheckedKeys(false));
- };
- const setCheckedNodes = () => {
- treeRef.value.setCheckedNodes(
- [
- {
- id: 5,
- label: "Level two 2-1",
- },
- {
- id: 9,
- label: "Level three 1-1-1",
- },
- ],
- false
- );
- };
- const setCheckedKeys = (keyArr) => {
- treeRef.value.setCheckedKeys(keyArr, false);
- };
- const resetChecked = () => {
- treeRef.value.setCheckedKeys([], false);
- };
- const defaultProps = {
- children: "children",
- label: "label",
- };
- defineExpose({ setCheckedKeys });
- </script>
- <style lang="less" scoped>
- .tree-wrapper {
- height: 100%;
- ;
- padding: 20px;
- .treeRef {
- height: calc(100% - 30px - 20px);
- width: 100%;
- margin-top: 10px;
- padding: 10px 0;
- overflow: auto;
- .dashboard-tree-title {
- display: flex;
- justify-content: space-between;
- width: 100%;
- }
- .refresh {
- margin-right: 15px;
- }
- }
- }
- .el-tree::v-deep {
- .el-tree-node__content:hover,
- .el-tree-node__content:active {
- background: rgba(97, 97, 90, 25%);
- }
- &.el-tree--highlight-current
- .el-tree-node.is-current
- > .el-tree-node__content {
- background: rgba(97, 97, 90, 25%);
- }
- }
- </style>
|