资源调整
This commit is contained in:
parent
35e8587ec5
commit
4dba932888
@ -30,14 +30,14 @@
|
|||||||
:src="item.lastRank ? lastIcon : item.showChild ? currentIcon : defaultIcon"></image>
|
:src="item.lastRank ? lastIcon : item.showChild ? currentIcon : defaultIcon"></image>
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
</view>
|
</view>
|
||||||
<!-- 多选时所有节点都显示多选框 -->
|
<!-- 只有叶子节点显示可选择的选择框 -->
|
||||||
<view class="tki-tree-check" v-if="multiple" @tap.stop="_treeItemSelect(item, index)">
|
<view class="tki-tree-check" @tap.stop="_treeItemSelect(item, index)" :class="{'disabled': !item.lastRank}">
|
||||||
<view class="tki-tree-check-yes" v-if="item.checked" :class="{'radio':!multiple}"
|
<view class="tki-tree-check-yes" v-if="item.checked" :class="{'radio':!multiple}"
|
||||||
:style="{'border-color':confirmColor}">
|
:style="{'border-color':confirmColor}">
|
||||||
<view class="tki-tree-check-yes-b" :style="{'background-color':confirmColor}"></view>
|
<view class="tki-tree-check-yes-b" :style="{'background-color':confirmColor}"></view>
|
||||||
</view>
|
</view>
|
||||||
<view class="tki-tree-check-no" v-else :class="{'radio':!multiple}"
|
<view class="tki-tree-check-no" v-else :class="{'radio':!multiple}"
|
||||||
:style="{'border-color':confirmColor}"></view>
|
:style="{'border-color': !item.lastRank ? '#ccc' : confirmColor}"></view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
@ -277,17 +277,16 @@ export default {
|
|||||||
// console.log(this.treeList)
|
// console.log(this.treeList)
|
||||||
},
|
},
|
||||||
_treeItemSelect(item, index) {
|
_treeItemSelect(item, index) {
|
||||||
|
// 只有叶子节点才能被选择
|
||||||
|
if (!item.lastRank) {
|
||||||
|
// 如果不是叶子节点,不允许选择
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
if (!item.lastRank) {
|
// 子节点单独切换
|
||||||
// 父节点多选框:全选/全不选所有子节点
|
this.treeList[index].checked = !this.treeList[index].checked;
|
||||||
const allChecked = this._isAllChildrenChecked(item);
|
this._updateParentChecked(item);
|
||||||
this._setAllChildrenChecked(item, !allChecked);
|
|
||||||
item.checked = !allChecked;
|
|
||||||
} else {
|
|
||||||
// 子节点单独切换
|
|
||||||
this.treeList[index].checked = !this.treeList[index].checked;
|
|
||||||
this._updateParentChecked(item);
|
|
||||||
}
|
|
||||||
this._fixMultiple(index);
|
this._fixMultiple(index);
|
||||||
} else {
|
} else {
|
||||||
// 单选逻辑
|
// 单选逻辑
|
||||||
@ -496,4 +495,14 @@ export default {
|
|||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tki-tree-check.disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tki-tree-check.disabled .tki-tree-check-no {
|
||||||
|
border-color: #ccc !important;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,15 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="add-resource-page">
|
<view class="add-resource-page">
|
||||||
<!-- 页面头部 -->
|
|
||||||
<view class="page-header">
|
|
||||||
<view class="header-left" @click="goBack">
|
|
||||||
<uni-icons type="left" size="20" color="#333"></uni-icons>
|
|
||||||
<text class="back-text">返回</text>
|
|
||||||
</view>
|
|
||||||
<view class="header-title">上传资源</view>
|
|
||||||
<view class="header-right"></view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 表单内容 -->
|
<!-- 表单内容 -->
|
||||||
<scroll-view scroll-y class="form-scroll-view">
|
<scroll-view scroll-y class="form-scroll-view">
|
||||||
<view class="form-container">
|
<view class="form-container">
|
||||||
@ -17,19 +7,12 @@
|
|||||||
<view class="info-card">
|
<view class="info-card">
|
||||||
<view class="form-item">
|
<view class="form-item">
|
||||||
<text class="form-label">资源目录 <text class="required">*</text></text>
|
<text class="form-label">资源目录 <text class="required">*</text></text>
|
||||||
<picker
|
<view class="picker-row" @click="showResourceTypeTree">
|
||||||
mode="selector"
|
<text :class="{ placeholder: !formData.resourType }">
|
||||||
:range="treeData"
|
{{ getResourceTypeText() || '请选择资源目录' }}
|
||||||
range-key="title"
|
</text>
|
||||||
@change="handleResourceTypeChange"
|
<uni-icons type="right" size="16" color="#999"></uni-icons>
|
||||||
>
|
</view>
|
||||||
<view class="picker-row">
|
|
||||||
<text :class="{ placeholder: !formData.resourType }">
|
|
||||||
{{ getResourceTypeText() || '请选择资源目录' }}
|
|
||||||
</text>
|
|
||||||
<uni-icons type="right" size="16" color="#999"></uni-icons>
|
|
||||||
</view>
|
|
||||||
</picker>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -136,13 +119,23 @@
|
|||||||
|
|
||||||
<!-- 底部提交按钮 -->
|
<!-- 底部提交按钮 -->
|
||||||
<view class="bottom-actions">
|
<view class="bottom-actions">
|
||||||
<button class="action-btn cancel-btn" @click="goBack">
|
|
||||||
取消
|
|
||||||
</button>
|
|
||||||
<button class="action-btn confirm-btn" @click="handleSubmitForm" :disabled="isSubmitting">
|
<button class="action-btn confirm-btn" @click="handleSubmitForm" :disabled="isSubmitting">
|
||||||
{{ isSubmitting ? '提交中...' : '提交' }}
|
{{ isSubmitting ? '提交中...' : '提交' }}
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 资源目录选择树 -->
|
||||||
|
<BasicTree
|
||||||
|
ref="treeRef"
|
||||||
|
:range="treeData"
|
||||||
|
idKey="key"
|
||||||
|
rangeKey="title"
|
||||||
|
title="选择资源目录"
|
||||||
|
:multiple="false"
|
||||||
|
:selectParent="false"
|
||||||
|
@confirm="onTreeConfirm"
|
||||||
|
@cancel="onTreeCancel"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -152,6 +145,7 @@ import { typesFindTreeApi } from "@/api/base/server";
|
|||||||
import { attachmentUpload } from "@/api/system/upload";
|
import { attachmentUpload } from "@/api/system/upload";
|
||||||
import { imagUrl } from "@/utils";
|
import { imagUrl } from "@/utils";
|
||||||
import { useDicStore } from "@/store/modules/dic";
|
import { useDicStore } from "@/store/modules/dic";
|
||||||
|
import BasicTree from "@/components/BasicTree/Tree.vue";
|
||||||
|
|
||||||
const { findByPid } = useDicStore();
|
const { findByPid } = useDicStore();
|
||||||
|
|
||||||
@ -182,6 +176,9 @@ const formData = reactive({
|
|||||||
// 树形数据
|
// 树形数据
|
||||||
const treeData = ref([]);
|
const treeData = ref([]);
|
||||||
|
|
||||||
|
// 树组件引用
|
||||||
|
const treeRef = ref();
|
||||||
|
|
||||||
// 提交状态
|
// 提交状态
|
||||||
const isSubmitting = ref(false);
|
const isSubmitting = ref(false);
|
||||||
|
|
||||||
@ -191,15 +188,29 @@ const categoryOptions = ref([]);
|
|||||||
// 加载资源类别数据
|
// 加载资源类别数据
|
||||||
const loadCategoryOptions = async () => {
|
const loadCategoryOptions = async () => {
|
||||||
try {
|
try {
|
||||||
|
// 使用正确的字典ID
|
||||||
const result = await findByPid({ pid: 1391443399 });
|
const result = await findByPid({ pid: 1391443399 });
|
||||||
if (result && Array.isArray(result)) {
|
|
||||||
categoryOptions.value = result.map(item => ({
|
// 检查返回的数据结构
|
||||||
|
if (result && result.resultCode === 1 && result.result && Array.isArray(result.result) && result.result.length > 0) {
|
||||||
|
categoryOptions.value = result.result.map(item => ({
|
||||||
value: item.dictionaryCode,
|
value: item.dictionaryCode,
|
||||||
label: item.dictionaryValue
|
label: item.dictionaryValue
|
||||||
}));
|
}));
|
||||||
|
} else {
|
||||||
|
// 如果没有数据,使用默认选项
|
||||||
|
categoryOptions.value = [
|
||||||
|
{ value: '1', label: '课件' },
|
||||||
|
{ value: '2', label: '教案' },
|
||||||
|
{ value: '3', label: '学案' },
|
||||||
|
{ value: '4', label: '作业' },
|
||||||
|
{ value: '5', label: '试卷' },
|
||||||
|
{ value: '6', label: '教材' },
|
||||||
|
{ value: '7', label: '示范课' },
|
||||||
|
{ value: '8', label: '音视频合集' },
|
||||||
|
];
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载资源类别失败:', error);
|
|
||||||
// 如果加载失败,使用默认选项
|
// 如果加载失败,使用默认选项
|
||||||
categoryOptions.value = [
|
categoryOptions.value = [
|
||||||
{ value: '1', label: '课件' },
|
{ value: '1', label: '课件' },
|
||||||
@ -214,16 +225,26 @@ const loadCategoryOptions = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 返回上一页
|
|
||||||
const goBack = () => {
|
|
||||||
uni.navigateBack();
|
// 显示资源目录选择树
|
||||||
|
const showResourceTypeTree = () => {
|
||||||
|
if (treeRef.value) {
|
||||||
|
treeRef.value._show();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 资源目录选择
|
// 树形选择确认
|
||||||
const handleResourceTypeChange = (e: any) => {
|
const onTreeConfirm = (selectedItems: any[]) => {
|
||||||
const index = e.detail.value;
|
if (selectedItems.length > 0) {
|
||||||
const selectedItem = treeData.value[index];
|
const selectedItem = selectedItems[0]; // 单选模式
|
||||||
formData.resourType = selectedItem.key;
|
formData.resourType = selectedItem.key;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 树形选择取消
|
||||||
|
const onTreeCancel = () => {
|
||||||
|
// 取消选择资源目录
|
||||||
};
|
};
|
||||||
|
|
||||||
// 资源类别选择
|
// 资源类别选择
|
||||||
@ -415,7 +436,7 @@ const handleSubmitForm = async () => {
|
|||||||
id: formData.id
|
id: formData.id
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('提交参数:', params);
|
|
||||||
|
|
||||||
const result = await resourcesSaveApi(params);
|
const result = await resourcesSaveApi(params);
|
||||||
|
|
||||||
@ -457,16 +478,45 @@ const resetFormData = () => {
|
|||||||
const loadTreeData = async () => {
|
const loadTreeData = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await typesFindTreeApi();
|
const res = await typesFindTreeApi();
|
||||||
treeData.value = res.result || [];
|
// 处理返回的数据结构,确保与BasicTree组件兼容
|
||||||
console.log('树形数据加载完成:', treeData.value);
|
if (res && Array.isArray(res)) {
|
||||||
|
treeData.value = res.map(item => ({
|
||||||
|
key: item.key || item.id,
|
||||||
|
title: item.title || item.name,
|
||||||
|
children: item.children ? item.children.map(child => ({
|
||||||
|
key: child.key || child.id,
|
||||||
|
title: child.title || child.name,
|
||||||
|
children: child.children || []
|
||||||
|
})) : []
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
treeData.value = res.result || [];
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载树形数据失败:', error);
|
|
||||||
|
// 如果加载失败,使用空数组
|
||||||
|
treeData.value = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取资源目录文本
|
// 获取资源目录文本
|
||||||
const getResourceTypeText = () => {
|
const getResourceTypeText = () => {
|
||||||
const selectedItem = treeData.value.find(item => item.key === formData.resourType);
|
// 递归查找选中的项目
|
||||||
|
const findSelectedItem = (items: any[], targetKey: string): any => {
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.key === targetKey) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
if (item.children && item.children.length > 0) {
|
||||||
|
const found = findSelectedItem(item.children, targetKey);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectedItem = findSelectedItem(treeData.value, formData.resourType);
|
||||||
return selectedItem ? selectedItem.title : '';
|
return selectedItem ? selectedItem.title : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -490,39 +540,7 @@ onMounted(async () => {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 20rpx 30rpx;
|
|
||||||
background-color: #ffffff;
|
|
||||||
border-bottom: 1rpx solid #f0f0f0;
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-left {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10rpx;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.back-text {
|
|
||||||
font-size: 28rpx;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-title {
|
|
||||||
font-size: 32rpx;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-right {
|
|
||||||
width: 80rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-scroll-view {
|
.form-scroll-view {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@ -671,19 +689,8 @@ onMounted(async () => {
|
|||||||
border-top: 1rpx solid #f0f0f0;
|
border-top: 1rpx solid #f0f0f0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cancel-btn {
|
|
||||||
flex: 1;
|
|
||||||
padding: 20rpx;
|
|
||||||
border-radius: 8rpx;
|
|
||||||
font-size: 28rpx;
|
|
||||||
font-weight: 500;
|
|
||||||
border: none;
|
|
||||||
background: #f5f5f5;
|
|
||||||
color: #666;
|
|
||||||
}
|
|
||||||
|
|
||||||
.confirm-btn {
|
.confirm-btn {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
|
|||||||
@ -230,7 +230,7 @@ export const previewFile = (fileUrl: string, fileName: string, fileType: string)
|
|||||||
const encodedUrl = btoa(finalFileUrl);
|
const encodedUrl = btoa(finalFileUrl);
|
||||||
console.log('使用kkFileView预览,Base64编码后的URL:', encodedUrl);
|
console.log('使用kkFileView预览,Base64编码后的URL:', encodedUrl);
|
||||||
|
|
||||||
const previewUrl = `http://yufangzc.com:8891/onlinePreview?url=${encodeURIComponent(encodedUrl)}`;
|
const previewUrl = `${KK_FILE_VIEW_URL}/onlinePreview?url=${encodeURIComponent(encodedUrl)}`;
|
||||||
console.log('最终预览URL (普通文件):', previewUrl);
|
console.log('最终预览URL (普通文件):', previewUrl);
|
||||||
|
|
||||||
const needLandscape = ['ppt', 'pptx'].includes(type);
|
const needLandscape = ['ppt', 'pptx'].includes(type);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user