EditEquipment.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <el-form ref="form" :model="form" label-width="120px">
  3. <el-form-item label="设备名称">
  4. <el-input v-model="form.name" size="mini"></el-input>
  5. </el-form-item>
  6. <el-form-item label="设备title">
  7. <el-input v-model="form.title" size="mini"></el-input>
  8. </el-form-item>
  9. <el-form-item label="设备描述">
  10. <el-input v-model="form.describe" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"></el-input>
  11. </el-form-item>
  12. <el-form-item label="顺序号">
  13. <el-input v-model="form.sort" type="number" size="mini"></el-input>
  14. </el-form-item>
  15. <el-form-item label="宣传图">
  16. <el-upload
  17. class="avatar-uploader"
  18. :action="uploadAction"
  19. :show-file-list="false"
  20. :on-success="onUploadSuccess"
  21. :before-upload="onBeforeUpload"
  22. >
  23. <img v-if="form.icon" :src="form.icon" class="avatar" />
  24. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  25. </el-upload>
  26. </el-form-item>
  27. <el-form-item label="设备内容">
  28. <div id="bar" class="bar"></div>
  29. <div id="editor" class="editor"></div>
  30. </el-form-item>
  31. <!-- <el-form-item label="跳转地址">
  32. <el-input v-model="form.url"></el-input>
  33. </el-form-item>-->
  34. <el-form-item>
  35. <el-button type="primary" @click="save" size="mini">保存</el-button>
  36. <el-button @click="goBack" size="mini">取消</el-button>
  37. </el-form-item>
  38. </el-form>
  39. </template>
  40. <script>
  41. var E = require("wangeditor");
  42. export default {
  43. data() {
  44. return {
  45. uploadAction: process.env.SERVER_PATH + "upload",
  46. form: {
  47. id: 0,
  48. name: "",
  49. title: "",
  50. icon: "",
  51. describe: "",
  52. sort: 0
  53. },
  54. html: "",
  55. editor: null
  56. };
  57. },
  58. watch: {
  59. html(newVal) {
  60. if (this.editor) {
  61. this.editor.txt.html(newVal);
  62. }
  63. }
  64. },
  65. methods: {
  66. save: function() {
  67. var that = this;
  68. this.$http
  69. .equipmentSave(
  70. {
  71. id: this.form.id,
  72. name: this.form.name,
  73. title: this.form.title,
  74. icon: this.form.icon,
  75. html: this.html,
  76. describe: this.form.describe,
  77. sort: this.form.sort
  78. },
  79. this
  80. )
  81. .then(res => {
  82. if (res.code === 0) {
  83. this.$message({
  84. message: "操作成功",
  85. type: "success",
  86. duration: 1000,
  87. onClose: function() {
  88. that.goBack();
  89. }
  90. });
  91. }
  92. });
  93. },
  94. goBack: function() {
  95. this.$router.back();
  96. },
  97. onBeforeUpload: function(file) {
  98. const isJPG = file.type === "image/jpeg";
  99. const isPNG = file.type === "image/png";
  100. if (!isJPG && !isPNG) {
  101. this.$message.error("上传商品图标只能是 JPG/PNG 格式!");
  102. return false;
  103. } else {
  104. return true;
  105. }
  106. },
  107. onUploadSuccess: function(res, file) {
  108. if (res.code != 0) {
  109. this.$message.error(
  110. "上传图片失败 原因:" + res.msg + "(" + res.code + ")"
  111. );
  112. return;
  113. } else {
  114. this.form.icon = res.obj;
  115. }
  116. }
  117. },
  118. mounted: function() {
  119. var that = this;
  120. var editor = new E("#bar", "#editor");
  121. editor.customConfig.uploadImgShowBase64 = true;
  122. //editor.customConfig.uploadImgServer = process.env.SERVER_PATH + 'editupload'
  123. //editor.customConfig.uploadFileName = 'file'
  124. editor.customConfig.onchange = function(html) {
  125. that.html = html;
  126. };
  127. editor.customConfig.colors = [
  128. '#00000000',
  129. '#000000',
  130. '#eeece0',
  131. '#1c487f',
  132. '#4d80bf',
  133. '#c24f4a',
  134. '#8baa4a',
  135. '#7b5ba1',
  136. '#46acc8',
  137. '#f9963b',
  138. '#ffffff'
  139. ];
  140. editor.create();
  141. this.editor = editor;
  142. var id = this.$route.query.id;
  143. if (id === 0) {
  144. return;
  145. }
  146. this.form.id = id;
  147. this.$http.equipmentGet({ id: id }, this).then(res => {
  148. if (res.code === 0) {
  149. this.form.name = res.obj.name;
  150. this.form.title = res.obj.title;
  151. this.form.icon = res.obj.icon;
  152. this.form.describe = res.obj.describe;
  153. this.html = res.obj.html;
  154. this.form.sort = res.obj.sort;
  155. }
  156. });
  157. }
  158. };
  159. </script>
  160. <style scoped>
  161. .w-e-text-container,
  162. .w-e-toolbar {
  163. border: 1px solid #dcdfe6;
  164. }
  165. .w-e-toolbar {
  166. border-bottom: none;
  167. }
  168. .avatar-uploader img {
  169. height: 100%;
  170. width: 100%;
  171. }
  172. .el-form-item {
  173. margin-bottom: 0px;
  174. }
  175. </style>