|
|
@@ -151,7 +151,7 @@
|
|
|
codeType: ''
|
|
|
};
|
|
|
return {
|
|
|
- activeName: '1',
|
|
|
+ activeName: '2',
|
|
|
|
|
|
templateVisible: false,
|
|
|
folderList: [],
|
|
|
@@ -208,17 +208,58 @@
|
|
|
setFolderList(this.folderList); //权限过滤
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 递归在树中按 name 查找节点
|
|
|
+ findNodeByName(tree, name) {
|
|
|
+ if (!tree || !tree.length) return null;
|
|
|
+ for (const node of tree) {
|
|
|
+ if (node.name === name) return node;
|
|
|
+ if (node.sonDirectoryList && node.sonDirectoryList.length) {
|
|
|
+ const found = this.findNodeByName(node.sonDirectoryList, name);
|
|
|
+ if (found) return found;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ // 默认 编码分类 = "文档"(在树中按名称查找,未找到时回退到 options[0].parentId)
|
|
|
+ applyDefaultCodeType() {
|
|
|
+ const docNode = this.findNodeByName(this.list, '文档');
|
|
|
+ if (docNode) {
|
|
|
+ this.form.codeType = docNode.id;
|
|
|
+ } else if (this.options && this.options.length > 0) {
|
|
|
+ this.form.codeType = this.options[0].parentId;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 默认 编码方案 = "通用文档编码"(在 options 中按名称查找,未找到时回退到第一个)
|
|
|
+ applyDefaultBusinessCode() {
|
|
|
+ if (!this.options || this.options.length === 0) {
|
|
|
+ this.form.businessCodeId = '';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const generalDoc = this.options.find(
|
|
|
+ (opt) => opt.name === '通用文档编码'
|
|
|
+ );
|
|
|
+ this.form.businessCodeId = generalDoc
|
|
|
+ ? generalDoc.id
|
|
|
+ : this.options[0].id;
|
|
|
+ },
|
|
|
handleClick() {
|
|
|
if (this.activeName == 2) {
|
|
|
this.folderList = this.myFolderList;
|
|
|
} else {
|
|
|
this.folderList = this.allFolderList;
|
|
|
}
|
|
|
- // 切换 tab 时使用新 tab 的默认值(文档位置 / 编码分类 / 编码方案)联动更新
|
|
|
- // 其他字段(type / 备注 / 已上传文件等)保留不动
|
|
|
+ // 切换 tab 时只更新 directoryId / options,保留用户已选的 codeType / businessCodeId
|
|
|
if (this.folderList && this.folderList.length > 0) {
|
|
|
- this.form.directoryId = this.folderList[0].id;
|
|
|
- this.initFileCode();
|
|
|
+ const firstFolder = this.folderList[0];
|
|
|
+ this.form.directoryId = firstFolder.id;
|
|
|
+ // 显式传 nodeData,避开 cascader 时序问题
|
|
|
+ this.initFileCode({
|
|
|
+ id: firstFolder.id,
|
|
|
+ parentId:
|
|
|
+ firstFolder.parentId != null && firstFolder.parentId !== 0
|
|
|
+ ? firstFolder.parentId
|
|
|
+ : ''
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
async getTreeCode() {
|
|
|
@@ -234,29 +275,66 @@
|
|
|
nodeData[0]?.data?.parentId != 0 ? nodeData[0]?.data?.parentId : ''
|
|
|
};
|
|
|
},
|
|
|
- async initFileCode() {
|
|
|
- await this.getTreeCode();
|
|
|
- this.options = this.nodeData.id ? await listCode(this.nodeData) : [];
|
|
|
- if (this.options.length > 0) {
|
|
|
- this.form.businessCodeId = this.options[0].id;
|
|
|
- this.form.codeType = this.options[0].parentId;
|
|
|
+ async initFileCode(forceNodeData) {
|
|
|
+ if (forceNodeData && forceNodeData.id) {
|
|
|
+ // 外部显式传入 nodeData,绕过 cascader 时序问题
|
|
|
+ this.nodeData = forceNodeData;
|
|
|
} else {
|
|
|
- this.form.businessCodeId = '';
|
|
|
+ await this.getTreeCode();
|
|
|
+ }
|
|
|
+ // 保留用户已选 codeType,只刷新 options(open() 中会先设默认值)
|
|
|
+ if (this.form.codeType) {
|
|
|
+ // 用 codeType 触发 listParentId 加载 options(与 typeChange 数据源一致)
|
|
|
+ await this.loadOptionsByCodeType(this.form.codeType);
|
|
|
+ } else {
|
|
|
+ // 回退:使用 listCode(按目录加载)
|
|
|
+ this.options = this.nodeData.id ? await listCode(this.nodeData) : [];
|
|
|
+ }
|
|
|
+ // 如果当前 businessCodeId 不在新的 options 中,重置为"通用文档编码"(默认)
|
|
|
+ if (this.options.find((opt) => opt.id === this.form.businessCodeId)) {
|
|
|
+ // 保留用户已选
|
|
|
+ } else {
|
|
|
+ this.applyDefaultBusinessCode();
|
|
|
}
|
|
|
},
|
|
|
+ // 按 编码分类 加载对应的 编码方案 options
|
|
|
+ async loadOptionsByCodeType(codeType) {
|
|
|
+ let obj = {
|
|
|
+ pageNum: 1,
|
|
|
+ size: 100,
|
|
|
+ parentId: codeType
|
|
|
+ };
|
|
|
+ if (this.activeName == 1) {
|
|
|
+ obj['objId'] = this.nodeData?.id;
|
|
|
+ obj['objParentId'] = this.nodeData?.parentId;
|
|
|
+ }
|
|
|
+ let data = await listParentId(obj);
|
|
|
+ this.options = data.list.filter((item) => item.type == 2);
|
|
|
+ },
|
|
|
async open() {
|
|
|
- // 每次重新打开都回到"文档工作区"标签
|
|
|
- this.activeName = '1';
|
|
|
- this.folderList = this.allFolderList;
|
|
|
+ // 默认进入"个人文档"标签
|
|
|
+ this.activeName = '2';
|
|
|
+ this.folderList = this.myFolderList;
|
|
|
this.showEditFlag = true;
|
|
|
this.$nextTick(async () => {
|
|
|
this.list = await selectTreeList();
|
|
|
- // 强制使用 文档工作区 的默认值(避免 cancel() 保留的旧 directoryId 导致默认值缺失)
|
|
|
+ // 默认 编码分类 = "文档"(仅在 open 时设置默认值,后续切 tab/改目录时保留用户选择)
|
|
|
+ this.applyDefaultCodeType();
|
|
|
+ // 强制使用 个人文档 的默认值(避免 cancel() 保留的旧 directoryId 导致默认值缺失)
|
|
|
if (this.folderList && this.folderList.length > 0) {
|
|
|
- this.form.directoryId = this.folderList[0].id;
|
|
|
+ const firstFolder = this.folderList[0];
|
|
|
+ this.form.directoryId = firstFolder.id;
|
|
|
+ // 显式构造 nodeData 并传入 initFileCode,避开 cascader getCheckedNodes 的时序问题
|
|
|
+ await this.initFileCode({
|
|
|
+ id: firstFolder.id,
|
|
|
+ parentId:
|
|
|
+ firstFolder.parentId != null && firstFolder.parentId !== 0
|
|
|
+ ? firstFolder.parentId
|
|
|
+ : ''
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ await this.initFileCode();
|
|
|
}
|
|
|
- // 触发 initFileCode,根据选中的文档位置默认填充 编码分类 / 编码方案
|
|
|
- await this.initFileCode();
|
|
|
// 文档类型默认值
|
|
|
if (!this.form.type) {
|
|
|
this.form.type = '1';
|
|
|
@@ -276,18 +354,10 @@
|
|
|
});
|
|
|
},
|
|
|
async typeChange(val) {
|
|
|
- let obj = {
|
|
|
- pageNum: 1,
|
|
|
- size: 100,
|
|
|
- parentId: val
|
|
|
- };
|
|
|
- if (this.activeName == 1) {
|
|
|
- obj['objId'] = this.nodeData?.id;
|
|
|
- obj['objParentId'] = this.nodeData?.parentId;
|
|
|
- }
|
|
|
- let data = await listParentId(obj);
|
|
|
- this.options = data.list.filter((item) => item.type == 2);
|
|
|
- this.form.businessCodeId = '';
|
|
|
+ // 切换 编码分类 后重新加载 options
|
|
|
+ await this.loadOptionsByCodeType(val);
|
|
|
+ // 默认选中"通用文档编码"(若存在),用户可自行修改
|
|
|
+ this.applyDefaultBusinessCode();
|
|
|
},
|
|
|
|
|
|
fileChange(file) {
|