dialog.vue 8.4 KB

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