dialog.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <el-dialog
  3. :title="`${type}统一门户`"
  4. :visible.sync="dialogVisible"
  5. width="25%"
  6. >
  7. <el-form label-width="150px" class="unifiedPortal-form" :model="form">
  8. <div class="icon-box">
  9. <div class="title">
  10. <div class="font">图标</div>
  11. <div>1.JPG/PNG格式</div>
  12. <div>2.大小不能超过10MB</div>
  13. <div>3.高宽比1:1</div>
  14. <div>4.推荐分辨率800*800</div>
  15. </div>
  16. <div class="img">
  17. <div class="avatar" v-if="imageUrl">
  18. <img :src="imageUrl" />
  19. <i @click="delImg" class="el-icon-close"></i>
  20. </div>
  21. <el-upload
  22. v-else
  23. class="avatar-uploader"
  24. :action="''"
  25. :auto-upload="false"
  26. :show-file-list="false"
  27. :on-change="handleAvatarChangeIcon"
  28. >
  29. <i class="el-icon-plus avatar-uploader-icon"></i>
  30. </el-upload>
  31. </div>
  32. </div>
  33. <!-- <el-form-item
  34. style="white-space: pre-wrap"
  35. label="图标(分辨率800*800)"
  36. required
  37. >
  38. <div class="avatar" v-if="imageUrl">
  39. <img :src="imageUrl" />
  40. <i @click="delImg" class="el-icon-close"></i>
  41. </div>
  42. <el-upload
  43. v-else
  44. class="avatar-uploader"
  45. :action="''"
  46. :auto-upload="false"
  47. :show-file-list="false"
  48. :on-change="handleAvatarChangeIcon"
  49. >
  50. <i class="el-icon-plus avatar-uploader-icon"></i>
  51. </el-upload>
  52. </el-form-item> -->
  53. <el-form-item label="名称" required>
  54. <el-input v-model="form.name" placeholder="请输入内容"></el-input>
  55. </el-form-item>
  56. <el-form-item label="排序" required>
  57. <el-input
  58. v-model="form.sort"
  59. type="number"
  60. placeholder="请输入内容"
  61. ></el-input>
  62. </el-form-item>
  63. <el-form-item label="链接" required>
  64. <el-input placeholder="请输入内容" v-model="form.linkUrl">
  65. <template slot="prepend">https://</template>
  66. </el-input>
  67. </el-form-item>
  68. <el-form-item label="链接类型" required>
  69. <DictSelection
  70. dictName="链接分类"
  71. :disabled="false"
  72. v-model="form.linkType"
  73. ></DictSelection>
  74. </el-form-item>
  75. <el-form-item label="架构类型" required>
  76. <DictSelection
  77. dictName="架构分类"
  78. :disabled="false"
  79. v-model="form.architType"
  80. ></DictSelection>
  81. </el-form-item>
  82. <el-form-item label="备注">
  83. <el-input v-model="form.remark" placeholder="请输入内容"></el-input>
  84. </el-form-item>
  85. </el-form>
  86. <div slot="footer" class="dialog-footer">
  87. <el-button size="small" @click="dialogVisible = false">关 闭</el-button>
  88. <el-button size="small" @click="config" type="primary">确 定</el-button>
  89. </div>
  90. </el-dialog>
  91. </template>
  92. <script>
  93. import { uploadFile } from '@/api/system/file/index.js';
  94. import {
  95. saveInfo,
  96. updateInfo,
  97. getDetails
  98. } from '@/api/system/unifiedPortal/index.js';
  99. export default {
  100. data() {
  101. return {
  102. dialogVisible: false,
  103. file: null,
  104. type: '新增',
  105. form: {
  106. linkType: '1',
  107. architType: '1'
  108. },
  109. imageUrl: '',
  110. options: [
  111. {
  112. label: '程序应用',
  113. value: '1'
  114. },
  115. {
  116. label: '网页应用',
  117. value: '2'
  118. }
  119. ]
  120. };
  121. },
  122. methods: {
  123. delImg() {
  124. this.imageUrl = '';
  125. this.file = null;
  126. },
  127. handleClose() {
  128. this.dialogVisible = false;
  129. },
  130. async open(type, id) {
  131. this.type = type;
  132. if (type == '新增') {
  133. this.form = {
  134. linkType: '1',
  135. architType: '1'
  136. };
  137. this.imageUrl = '';
  138. this.file = null;
  139. } else {
  140. this.file = null;
  141. this.form = await getDetails(id);
  142. this.imageUrl =
  143. window.location.origin +
  144. '/api/main/file/getFile?objectName=' +
  145. this.form.iconPath;
  146. }
  147. this.dialogVisible = true;
  148. },
  149. handleAvatarChangeIcon(file, fileList) {
  150. //选中文件触发的change事件
  151. console.log(file);
  152. const isJPG = file.raw.type === 'image/jpeg';
  153. const isPNG = file.raw.type === 'image/png';
  154. const isLt10M = file.raw.size / 1024 / 1024 < 10; //限制上传文件的大小
  155. if (!isLt10M) {
  156. this.$message.error('上传文件大小不能超过 10MB!');
  157. return false;
  158. }
  159. if (!isPNG && !isJPG) {
  160. this.$message.error('上传图片只能是 JPG/PNG 格式!');
  161. return false;
  162. } else {
  163. this.imageUrl = URL.createObjectURL(file.raw); //赋值图片的url,用于图片回显功能
  164. this.file = file.raw; //赋值文件对象,用于上传操作
  165. }
  166. },
  167. async config() {
  168. if (!this.form.name) {
  169. return this.$message.error('请输入名称');
  170. }
  171. if (this.form.sort < 0) {
  172. return this.$message.error('请输入排序');
  173. }
  174. if (!this.form.linkUrl) {
  175. return this.$message.error('请输入链接');
  176. }
  177. if (this.form.linkType < 0) {
  178. return this.$message.error('请选择链接类型');
  179. }
  180. if (this.form.architType < 0) {
  181. return this.$message.error('请选择架构类型');
  182. }
  183. // 文件上传操作
  184. if (this.file) {
  185. try {
  186. let res = await uploadFile({
  187. multiPartFile: this.file,
  188. module: 'gateway'
  189. });
  190. this.form.icon = res.data.id;
  191. } catch (error) {
  192. console.log(error);
  193. return this.$message.error('上传文件失败');
  194. }
  195. } else {
  196. if (this.type == '新增') {
  197. return this.$message.error('请上传图片');
  198. }
  199. }
  200. if (this.type == '新增') {
  201. // 保存数据
  202. try {
  203. await saveInfo(this.form);
  204. this.$message.success('新增成功');
  205. this.dialogVisible = false;
  206. this.$emit('reload');
  207. } catch (error) {
  208. console.log(error);
  209. this.$message.error('新增失败');
  210. }
  211. } else {
  212. // 修改
  213. try {
  214. await updateInfo(this.form);
  215. this.$message.success('修改成功');
  216. this.dialogVisible = false;
  217. this.$emit('reload');
  218. } catch (error) {
  219. this.$message.error('修改失败');
  220. }
  221. }
  222. }
  223. }
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. .unifiedPortal-form {
  228. .icon-box {
  229. display: flex;
  230. margin-bottom: 10px;
  231. .title {
  232. flex: 0 0 150px;
  233. display: flex;
  234. flex-direction: column;
  235. justify-content: center;
  236. .font:before {
  237. content: '*';
  238. color: red;
  239. margin-right: 4px;
  240. }
  241. }
  242. .img {
  243. flex: 1;
  244. }
  245. }
  246. }
  247. .typeSelect {
  248. width: 100%;
  249. }
  250. .avatar-uploader {
  251. height: 120px;
  252. width: 100%;
  253. }
  254. .avatar {
  255. width: 120px;
  256. height: 120px;
  257. position: relative;
  258. border: 1px solid #d9d9d9;
  259. > img {
  260. width: 100%;
  261. height: 100%;
  262. object-fit: cover;
  263. }
  264. .el-icon-close {
  265. cursor: pointer;
  266. position: absolute;
  267. top: 0;
  268. right: 0;
  269. color: #000;
  270. }
  271. }
  272. .avatar-uploader-icon {
  273. width: 120px;
  274. height: 120px;
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. border: 1px dashed #d9d9d9;
  279. }
  280. </style>