addRoot.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div>
  3. <el-alert title="教材信息" :closable="false" class="alert" type="info" />
  4. <el-form :model="form" label-width="120px" class="form" ref="form">
  5. <el-form-item
  6. label="教材名称"
  7. prop="name"
  8. :rules="[
  9. {
  10. required: true,
  11. message: '请输入教材名称',
  12. trigger: 'blur',
  13. },
  14. ]"
  15. >
  16. <el-input
  17. v-model="form.name"
  18. placeholder="请输入教材名称"
  19. style="width: 100%"
  20. ></el-input>
  21. </el-form-item>
  22. <el-form-item
  23. label="音源设置"
  24. prop="soundResource"
  25. v-if="level <= 1 && level == 1 && type != 'create'"
  26. :rules="[
  27. {
  28. required: true,
  29. message: '请选择音源设置',
  30. trigger: 'change',
  31. },
  32. ]"
  33. >
  34. <el-select
  35. filterable
  36. placeholder="请选择音源设置"
  37. clearable
  38. v-model="form.soundResource"
  39. style="width: 100% !important"
  40. >
  41. <el-option label="NotePerformer音源" value="NOTEPERFORMER"></el-option>
  42. <el-option label="标准音源" value="TANG"></el-option>
  43. <el-option label="官方音源" value="OFFICIAL"></el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item
  47. label="教材封面图"
  48. prop="coverImg"
  49. :rules="[
  50. {
  51. required: level > 1 ? false : true,
  52. message: '请上传教材封面图',
  53. trigger: 'blur',
  54. },
  55. ]"
  56. label-width="120px"
  57. >
  58. <!-- <upload
  59. :class="[imageWidthM == 350 ? 'uploadImg' : 'uploadSmallImg']"
  60. v-model="form.coverImg"
  61. :imageWidthM="imageWidthM"
  62. :imageHeightM="imageHeightM"
  63. ref="uploadImg"
  64. ></upload> -->
  65. <image-cropper
  66. :options="cropperOptions"
  67. bucket_name="cloud-coach"
  68. :imgSize="2"
  69. :imageUrl="form.coverImg"
  70. showSize
  71. @crop-upload-success="cropSuccess"
  72. />
  73. <p style="color: red">大小2M以内,格式为jpg、png、gif图片</p>
  74. </el-form-item>
  75. </el-form>
  76. <span slot="footer" class="dialog-footer">
  77. <el-button @click="$listeners.close()">取 消</el-button>
  78. <el-button type="primary" @click="addSubmit">确 定</el-button>
  79. </span>
  80. </div>
  81. </template>
  82. <script>
  83. import Upload from "@/components/Upload/index";
  84. import ImageCropper from "@/components/ImageCropper";
  85. import { addsysMusicScore, getSysMusicScoreDetail, resetsysMusicScore } from "../api";
  86. export default {
  87. props: ["type", "activeRow"],
  88. components: {
  89. Upload,
  90. ImageCropper,
  91. },
  92. data() {
  93. return {
  94. imageWidthM: 350,
  95. imageHeightM: 140,
  96. form: {
  97. organId: [],
  98. name: null,
  99. coverImg: "",
  100. soundResource: null,
  101. sysMusicScoreCategoriesList: [],
  102. // delCategoriesIds: [],
  103. },
  104. index: 0,
  105. treeProps: {
  106. children: "sysMusicScoreCategoriesList",
  107. label: "name",
  108. },
  109. level: 0, // 当前添加或修改第几层
  110. cropperOptions: {
  111. autoCrop: true, //是否默认生成截图框
  112. autoCropWidth: 350, //默认生成截图框宽度
  113. autoCropHeight: 140, //默认生成截图框高度
  114. fixedBox: true, //是否固定截图框大小 不允许改变
  115. previewsCircle: false, //预览图是否是圆形
  116. full: true, // 是否输出原图比例的截图
  117. enlarge: 2,
  118. title: "教材封面图", //模态框上显示的标题
  119. },
  120. };
  121. },
  122. async mounted() {
  123. await this.$store.dispatch("setBranchs");
  124. if (this.activeRow?.id) {
  125. // 判断是否是根元素处理
  126. if (this.activeRow?.parentId != 0 || this.type == "create") {
  127. // this.imageWidthM = 210
  128. // this.imageHeightM = 268
  129. this.cropperOptions.autoCropWidth = 210;
  130. this.cropperOptions.autoCropHeight = 268;
  131. }
  132. console.log(this.activeRow, "level");
  133. this.level = this.activeRow?.level || 0;
  134. try {
  135. const res = await getSysMusicScoreDetail({ id: this.activeRow.id });
  136. if (this.type == "create") {
  137. // 添加一级分类或子级
  138. this.form.organId = res.data.organId.split(",").map((item) => {
  139. return Number(item);
  140. });
  141. } else if (this.type == "update") {
  142. // 修改分类
  143. this.form.name = res.data.name;
  144. this.form.organId = res.data.organId.split(",").map((item) => {
  145. return Number(item);
  146. });
  147. this.form.coverImg = res.data.coverImg;
  148. this.form.soundResource = res.data.soundResource;
  149. }
  150. } catch (e) {}
  151. }
  152. },
  153. methods: {
  154. formatParentId(id, list, ids = []) {
  155. for (const item of list) {
  156. if (item.sysMusicScoreCategoriesList) {
  157. const cIds = this.formatParentId(id, item.sysMusicScoreCategoriesList, [
  158. ...ids,
  159. item.id,
  160. ]);
  161. if (cIds.includes(id)) {
  162. return cIds;
  163. }
  164. }
  165. if (item.id === id) {
  166. return [...ids, id];
  167. }
  168. }
  169. return ids;
  170. },
  171. addSubmit() {
  172. this.$refs.form.validate(async (flag) => {
  173. if (flag) {
  174. let { organId, ...rest } = this.form;
  175. let parentId = 0;
  176. if (this.type == "create") {
  177. parentId = this.activeRow?.id || 0;
  178. } else if (this.type == "update") {
  179. parentId = this.activeRow?.parentId || 0;
  180. }
  181. let obj = {
  182. ...rest,
  183. parentId,
  184. organId: organId.join(","),
  185. };
  186. try {
  187. if (this.type == "update") {
  188. obj.id = this.activeRow?.id;
  189. await resetsysMusicScore(obj);
  190. this.$message.success("修改成功");
  191. this.$emit("getList");
  192. this.$emit("close");
  193. } else {
  194. await addsysMusicScore(obj);
  195. this.$message.success("添加成功");
  196. this.$emit("getList");
  197. this.$emit("close");
  198. }
  199. } catch (e) {
  200. console.log(e);
  201. }
  202. }
  203. });
  204. },
  205. uploadImg() {
  206. this.$refs.uploadImg.$refs.upload.submit();
  207. },
  208. //上传操作结束
  209. cropClose() {
  210. console.log("上传操作结束");
  211. },
  212. //上传图片成功
  213. cropSuccess(data) {
  214. // this.imgUrl = data.data.avatar
  215. this.form.coverImg = data.data.url;
  216. console.log(this.form.coverImg);
  217. },
  218. },
  219. computed: {},
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .dialog-footer {
  224. display: block;
  225. text-align: right;
  226. }
  227. .alert {
  228. margin-bottom: 20px;
  229. }
  230. .form {
  231. ::v-deep .el-form-item {
  232. margin-right: 0 !important;
  233. }
  234. }
  235. .addCateBtn {
  236. margin-bottom: 20px;
  237. }
  238. .custom-tree-node {
  239. .title {
  240. font-size: 16px;
  241. }
  242. font-size: 14px;
  243. i {
  244. // font-size: 20px;
  245. margin-left: 5px;
  246. }
  247. }
  248. .uploadImg {
  249. ::v-deep .avatar {
  250. width: 350px;
  251. height: 140px;
  252. }
  253. }
  254. .uploadSmallImg {
  255. ::v-deep .avatar {
  256. width: 105px;
  257. height: 134px;
  258. }
  259. }
  260. </style>