background.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <section>
  3. <div id="child_menu">
  4. <div class="left">
  5. <label>行数</label>
  6. <input type="text" style="width: 40px" v-model="sum_copy"/>
  7. <label @click="changeSum" style="cursor: pointer">确认</label>
  8. </div>
  9. <div class="right">
  10. <label>设置</label> &nbsp;&nbsp;&nbsp; <label>删除</label>
  11. </div>
  12. </div>
  13. <child v-bind:sum="this.sum"></child>
  14. <div id="setting" >
  15. <div id="Attribute">
  16. <div style="color: red;font-weight: bolder;text-align: center;font-size: 14px;">背景图</div>
  17. <table :title="form && form.id ? '编辑' : '新增' " :model="form">
  18. <tr>
  19. <td>名称</td>
  20. <td colspan="3"><input type="text" style="width: 108px" v-model="form_copy.name"/></td>
  21. </tr>
  22. <tr>
  23. <td>图宽</td>
  24. <td><input type="text" v-model="form_copy.width" /></td>
  25. <td>图高</td>
  26. <td><input type="text" v-model="form_copy.height"/></td>
  27. </tr>
  28. <tr>
  29. <td colspan="4" style="text-align:left">
  30. 清晰度 <input type="text" v-model="form_copy.opacity" />%
  31. &nbsp;
  32. <button type="primary" @click="chooseType" style="float:right">上传</button>
  33. <input @change="fileChange($event)" type="file" id="upload_file" multiple style="display: none"/>
  34. </td>
  35. </tr>
  36. <tr>
  37. <td colspan="4" style="text-align:center;width:156px;" >
  38. <button type="primary" style="width:42px" @click="fittingPreview">预览</button>
  39. &nbsp;
  40. <button type="primary" style="width:42px;" @click="fileUpload">提交</button>
  41. &nbsp;
  42. <button type="primary" style="width:42px" @click="fittingSave">删除</button>
  43. </td>
  44. </tr>
  45. </table>
  46. </div>
  47. <div id="fitting">
  48. <img v-bind:src="form.src" id="fitting_img" v-bind:style="{width:form.width+'px',height:form.height+'px',opacity:form.opacity/100}"/>
  49. </div>
  50. </div>
  51. </section>
  52. </template>
  53. <script>
  54. import child from '@/components/common/list';
  55. let findAll = function() {
  56. this.$axios.get("/api/background/background/findAll").then(response => {
  57. if (response.data.code == 0) {
  58. this.rows = response.data.list;
  59. }
  60. })
  61. .catch(error => {
  62. console.log(error);
  63. this.message = error;
  64. });
  65. };
  66. let fittingSave = function(){
  67. this.$axios.post("/api/background/background/saveOrUpdate", this.form).then(response => {
  68. if (response.data.code == 0) {
  69. this.findAll()
  70. this.form = {}
  71. }
  72. })
  73. .catch(error => {
  74. console.log(error);
  75. this.message = error;
  76. });
  77. }
  78. let fittingEdit = function(index){
  79. this.form = this.rows[index]
  80. }
  81. let settingShow = function(){
  82. this.form = {}
  83. }
  84. let chooseType = function(){
  85. document.getElementById('upload_file').click();
  86. }
  87. let fileChange = function(el){
  88. if (!el.target.files[0].size) return;
  89. this.fileAdd(el.target.files[0]);
  90. el.target.value = ''
  91. }
  92. let fileAdd = function(file){
  93. //总大小
  94. if(file.size>3145728){
  95. alert('请选择3M以内的图片!');
  96. return false;
  97. }
  98. //判断是否为图片文件
  99. if (file.type.indexOf('image') == -1) {
  100. this.$dialog.toast({mes: '请选择图片文件'});
  101. return false;
  102. } else {
  103. let reader = new FileReader();
  104. let image = new Image();
  105. let _this = this;
  106. _this.file = file;
  107. reader.readAsDataURL(file);
  108. reader.onload = function () {
  109. _this.form.src = this.result;
  110. }
  111. }
  112. }
  113. let fileUpload = function(){
  114. let formData = new FormData();
  115. formData.append("file", this.file);
  116. this.$axios.post("/api/background/background/upload", formData).then(response => {
  117. if (response.data.code == 0) {
  118. this.form.src = response.data.url;
  119. this.fittingSave()
  120. }
  121. })
  122. .catch(error => {
  123. console.log(error);
  124. this.message = error;
  125. });
  126. }
  127. let changeSum = function(){
  128. this.sum = this.sum_copy * 8
  129. }
  130. let fittingPreview = function(){
  131. this.form = Object.assign({}, this.form_copy)
  132. }
  133. export default {
  134. data() {
  135. return {
  136. rows: [],
  137. form: {
  138. src:"img.jpg"
  139. },
  140. sum:1,
  141. sum_copy:1,
  142. file: '',
  143. form_copy: {
  144. src:"img.jpg"
  145. }
  146. };
  147. },
  148. mounted: function() {
  149. this.findAll();
  150. },
  151. methods: {
  152. findAll,
  153. fittingSave,
  154. fittingEdit,
  155. settingShow,
  156. chooseType,
  157. fileChange,
  158. fileAdd,
  159. fileUpload,
  160. changeSum,
  161. fittingPreview
  162. },
  163. components:{
  164. child
  165. }
  166. };
  167. </script>
  168. <style scoped>
  169. #Attribute {
  170. border: 1px solid #000;
  171. padding: 35px 30px;
  172. background: #f6fbfe;
  173. width: 155px;
  174. }
  175. #Attribute table tr :nth-child(odd) {
  176. text-align: right;
  177. width: 30px;
  178. }
  179. #Attribute table tr td {
  180. height: 37px;
  181. }
  182. #Attribute table tr td input {
  183. width: 40px;
  184. }
  185. #setting > div {
  186. float: right;
  187. text-align: center;
  188. }
  189. #fitting img {
  190. width: 350px;
  191. height: 200px;
  192. border: 1px solid #000;
  193. text-align: center;
  194. }
  195. </style>