file-edit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="500px"
  5. :visible.sync="showEditFlag"
  6. :close-on-click-modal="false"
  7. custom-class="ele-dialog-form"
  8. append-to-body
  9. @close="cancel"
  10. :title="title"
  11. ref="Emodal"
  12. :maxable="true"
  13. :resizable="true"
  14. >
  15. <el-tabs
  16. v-model="activeName"
  17. type="card"
  18. @tab-click="handleClick"
  19. style="margin-bottom: 10px"
  20. >
  21. <el-tab-pane label="文档工作区" name="1"></el-tab-pane>
  22. <el-tab-pane label="个人文档" name="2"></el-tab-pane>
  23. </el-tabs>
  24. <el-form ref="form" :model="form" :rules="rules" label-width="82px">
  25. <el-row :gutter="15">
  26. <el-col :span="24">
  27. <el-form-item label="文档位置" prop="directoryId">
  28. <el-cascader
  29. style="width: 100%"
  30. v-model="form.directoryId"
  31. :options="folderList"
  32. @change="initFileCode"
  33. ref="cascaderRef"
  34. :props="{
  35. value: 'id',
  36. label: 'name',
  37. children: 'sonDirectoryList',
  38. emitPath: false,
  39. checkStrictly: true
  40. }"
  41. ></el-cascader>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="24">
  45. <el-form-item label="编码分类" prop="codeType">
  46. <ele-tree-select
  47. clearable
  48. :data="list"
  49. v-model="form.codeType"
  50. placeholder="请选择"
  51. default-expand-all
  52. labelKey="name"
  53. childrenKey="sonDirectoryList"
  54. valueKey="id"
  55. @change="typeChange"
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="24">
  60. <el-form-item label="编码方案" prop="businessCodeId">
  61. <el-select
  62. v-model="form.businessCodeId"
  63. placeholder="请选择"
  64. style="width: 100%"
  65. >
  66. <el-option
  67. v-for="item in options"
  68. :key="item.id"
  69. :label="item.name"
  70. :value="item.id"
  71. >
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="24">
  77. <el-form-item label="文档类型" prop="type">
  78. <DictSelection
  79. dictName="文档类型"
  80. v-model="form.type"
  81. ></DictSelection>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="24">
  85. <el-form-item label="文档" prop="storagePath">
  86. <div style="display: flex; align-items: center">
  87. <fileUpload
  88. v-model="form.storagePath"
  89. module="main"
  90. :limit="100"
  91. :multiple="true"
  92. :beforeUploadFile="checkNameBeforeUpload"
  93. @fileChange="fileChange"
  94. >
  95. </fileUpload>
  96. </div>
  97. </el-form-item>
  98. </el-col>
  99. <el-col :span="24">
  100. <el-form-item label="备注" prop="remark">
  101. <el-input
  102. v-model="form.remark"
  103. type="textarea"
  104. placeholder="请输入"
  105. ></el-input>
  106. </el-form-item>
  107. </el-col>
  108. </el-row>
  109. </el-form>
  110. <template v-slot:footer>
  111. <el-button @click="cancel">取消</el-button>
  112. <el-button type="primary" :loading="loading" @click="save">
  113. 确认
  114. </el-button>
  115. </template>
  116. </ele-modal>
  117. </template>
  118. <script>
  119. import {
  120. fileSaveAPI,
  121. selectTreeList,
  122. listParentId,
  123. getDocTreeListAPI,
  124. listCode,
  125. checkNameExistsAPI
  126. } from './api/index';
  127. import FileUpload from './fileUpload.vue';
  128. import { setFolderList } from './util.js';
  129. import { mapGetters } from 'vuex';
  130. export default {
  131. components: { FileUpload },
  132. data() {
  133. const defaultForm = {
  134. name: '', //名称
  135. type: '1', //类型
  136. sizeUnit: '', //大小,
  137. unit: '', //单位
  138. remark: '', //备注
  139. status: '', //状态
  140. storagePathId: '',
  141. directoryId: '',
  142. businessCodeId: '',
  143. storagePath: [],
  144. id: '',
  145. lcyStatus: 1,
  146. fileType: 0,
  147. codeType: ''
  148. };
  149. return {
  150. activeName: '1',
  151. templateVisible: false,
  152. folderList: [],
  153. allFolderList: [],
  154. myFolderList: [],
  155. list: [],
  156. options: [],
  157. defaultForm,
  158. code: '',
  159. // 表单数据
  160. form: { ...defaultForm },
  161. // 提交状态
  162. loading: false,
  163. showEditFlag: false,
  164. title: '',
  165. type: '新建附件',
  166. nodeData: {}
  167. };
  168. },
  169. computed: {
  170. // 是否开启响应式布局
  171. styleResponsive() {
  172. return this.$store.state.theme.styleResponsive;
  173. },
  174. ...mapGetters(['user']),
  175. rules() {
  176. return {
  177. businessCodeId: [
  178. { required: true, message: '请选择', trigger: 'blur' }
  179. ],
  180. codeType: [
  181. {
  182. required: this.activeName == 2 ? true : false,
  183. message: '请选择',
  184. trigger: 'blur'
  185. }
  186. ],
  187. directoryId: [{ required: true, message: '请选择', trigger: 'blur' }],
  188. storagePath: [{ required: true, message: '请选择', trigger: 'blur' }]
  189. };
  190. }
  191. },
  192. async created() {
  193. this.allFolderList = await getDocTreeListAPI({
  194. type: 0,
  195. currentUserId: this.user.info.userId
  196. });
  197. this.myFolderList = await getDocTreeListAPI({
  198. type: 1,
  199. currentUserId: this.user.info.userId
  200. });
  201. this.folderList = this.allFolderList;
  202. setFolderList(this.folderList); //权限过滤
  203. },
  204. methods: {
  205. handleClick() {
  206. if (this.activeName == 2) {
  207. this.folderList = this.myFolderList;
  208. } else {
  209. this.folderList = this.allFolderList;
  210. }
  211. // 切换 tab 时使用新 tab 的默认值(文档位置 / 编码分类 / 编码方案)联动更新
  212. // 其他字段(type / 备注 / 已上传文件等)保留不动
  213. if (this.folderList && this.folderList.length > 0) {
  214. this.form.directoryId = this.folderList[0].id;
  215. this.initFileCode();
  216. }
  217. },
  218. async getTreeCode() {
  219. let nodeData = {};
  220. await this.$nextTick(() => {
  221. // console.log(this.$refs,'this.$refs')
  222. nodeData =
  223. this.$refs.cascaderRef && this.$refs.cascaderRef.getCheckedNodes();
  224. });
  225. this.nodeData = {
  226. id: nodeData[0]?.data?.id,
  227. parentId:
  228. nodeData[0]?.data?.parentId != 0 ? nodeData[0]?.data?.parentId : ''
  229. };
  230. },
  231. async initFileCode() {
  232. await this.getTreeCode();
  233. this.options = this.nodeData.id ? await listCode(this.nodeData) : [];
  234. if (this.options.length > 0) {
  235. this.form.businessCodeId = this.options[0].id;
  236. this.form.codeType = this.options[0].parentId;
  237. } else {
  238. this.form.businessCodeId = '';
  239. }
  240. },
  241. async open() {
  242. // 每次重新打开都回到"文档工作区"标签
  243. this.activeName = '1';
  244. this.folderList = this.allFolderList;
  245. this.showEditFlag = true;
  246. this.$nextTick(async () => {
  247. this.list = await selectTreeList();
  248. // 强制使用 文档工作区 的默认值(避免 cancel() 保留的旧 directoryId 导致默认值缺失)
  249. if (this.folderList && this.folderList.length > 0) {
  250. this.form.directoryId = this.folderList[0].id;
  251. }
  252. // 触发 initFileCode,根据选中的文档位置默认填充 编码分类 / 编码方案
  253. await this.initFileCode();
  254. // 文档类型默认值
  255. if (!this.form.type) {
  256. this.form.type = '1';
  257. }
  258. this.setTree(this.list);
  259. });
  260. },
  261. setTree(data) {
  262. data.forEach((item) => {
  263. item.sonDirectoryList = item.sonDirectoryList.filter(
  264. (item) => item.type == 1
  265. );
  266. if (item.sonDirectoryList.length > 0) {
  267. this.setTree(item.sonDirectoryList);
  268. }
  269. });
  270. },
  271. async typeChange(val) {
  272. let obj = {
  273. pageNum: 1,
  274. size: 100,
  275. parentId: val
  276. };
  277. if (this.activeName == 1) {
  278. obj['objId'] = this.nodeData?.id;
  279. obj['objParentId'] = this.nodeData?.parentId;
  280. }
  281. let data = await listParentId(obj);
  282. this.options = data.list.filter((item) => item.type == 2);
  283. this.form.businessCodeId = '';
  284. },
  285. fileChange(file) {
  286. this.form.name = file.name.replace(/\.[^/.]+$/, '');
  287. },
  288. // 上传前查重:返回 false 取消上传;返回 Promise<boolean> 异步判断
  289. async checkNameBeforeUpload(file) {
  290. try {
  291. const nameWithoutExt = file.name.replace(/\.[^/.]+$/, '');
  292. const duplicates = await checkNameExistsAPI([nameWithoutExt]);
  293. console.log(duplicates, 'duplicates1');
  294. if (!duplicates || duplicates.length === 0) {
  295. return true;
  296. }
  297. try {
  298. await this.$confirm(
  299. `以下文件名称已存在:${duplicates.join('、')},是否继续上传?`,
  300. '重名提示',
  301. {
  302. type: 'warning',
  303. confirmButtonText: '继续上传',
  304. cancelButtonText: '取消上传'
  305. }
  306. );
  307. return true;
  308. } catch {
  309. return false;
  310. }
  311. } catch (e) {
  312. // 查重接口异常 → 放行
  313. return true;
  314. }
  315. },
  316. /* 保存编辑 */
  317. save() {
  318. this.$refs.form.validate(async (valid) => {
  319. if (!valid) {
  320. return false;
  321. }
  322. let data = {
  323. ...this.form
  324. };
  325. if (this.activeName == 2) {
  326. data.fileType = 1;
  327. }
  328. this.loading = true;
  329. fileSaveAPI(data)
  330. .then((msg) => {
  331. this.loading = false;
  332. this.cancel();
  333. this.$emit('done', msg);
  334. })
  335. .catch((e) => {
  336. this.loading = false;
  337. });
  338. });
  339. },
  340. cancel() {
  341. this.form = { ...this.defaultForm, directoryId: this.form.directoryId };
  342. this.$refs.form.clearValidate();
  343. this.showEditFlag = false;
  344. }
  345. }
  346. };
  347. </script>
  348. <style scoped lang="scss">
  349. .aaa {
  350. width: 100%;
  351. ::v-deep .upload-demo {
  352. width: 100%;
  353. .el-upload--text {
  354. width: 100%;
  355. button {
  356. width: 100%;
  357. background: #ffffff;
  358. border: 1px solid #dbdbdb;
  359. border-radius: 5px;
  360. }
  361. }
  362. .el-upload-list {
  363. transform: translate(10px, -39px);
  364. position: absolute;
  365. }
  366. }
  367. }
  368. </style>