Import.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <el-dialog title="导入" @close="closeDialog" :close-on-click-modal="false" v-if="visible" :visible.sync="visible" append-to-body>
  3. <el-form style="margin-top:20px" :model="model" ref="form" @submit.native.prevent @keyup.enter.native="dataFormSubmit()" label-width="80px">
  4. <el-form-item label="模板文件" prop="file" verify :maxLength="255" label-width="100px" class="is-required exportFile">
  5. <el-input v-model="model.file" style="display:none;width:100%;height:100%"></el-input>
  6. <div class="btnUpfileBox">
  7. <div class="filename">{{ this.model.file }}<span v-if="!this.model.file" style="color: rgb(204, 204, 204);">(请选择上传文件)</span></div>
  8. <el-button type="primary" @click="uploadTrigger">点击上传<i class="el-icon-upload el-icon--right"></i></el-button>
  9. </div>
  10. <input type="file" @change="onDataFileSelect" style="display:none;width:100%;height:100%" ref="upFilesDataRef" />
  11. </el-form-item>
  12. <el-form-item label="模板名称" prop="name" verify :maxLength="255" label-width="100px" class="is-required">
  13. <el-input v-model="model.name"></el-input>
  14. </el-form-item>
  15. <el-form-item label="模板key" prop="key" verify :maxLength="255" label-width="100px" class="is-required">
  16. <el-input v-model="model.key"></el-input>
  17. </el-form-item>
  18. <el-form-item label="模型描述" prop="description" class="is-required" verify label-width="100px" :maxLength="200">
  19. <el-input type="textarea" v-model="model.description"></el-input>
  20. </el-form-item>
  21. <el-form-item label="模型分类" verify can-be-empty label-width="100px" :maxLength="200">
  22. <el-input v-model="model.category"></el-input>
  23. </el-form-item>
  24. </el-form>
  25. <span slot="footer" class="dialog-footer">
  26. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  27. <el-button @click="visible = false">关闭</el-button>
  28. </span>
  29. </el-dialog>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. formAction: 0, //0 add,//1,edit
  36. visible: false,
  37. title: '添加',
  38. disabled: false,
  39. btn: '提交',
  40. aproveVisible: false,
  41. model: {
  42. file: '',
  43. name: '',
  44. key: '',
  45. description: '',
  46. category: ''
  47. },
  48. filesData: '',
  49. filename: ''
  50. }
  51. },
  52. created() {},
  53. activated() {},
  54. methods: {
  55. init(id) {
  56. Object.assign(this.$data, this.$options.data.call(this))
  57. this.visible = true
  58. if (id) {
  59. let self = this
  60. var obj = {
  61. url: this.$url.workflowdef.getById,
  62. data: {
  63. id: id
  64. }
  65. }
  66. this.common.httpPost(obj, success)
  67. function success(data) {
  68. self.model = data.data
  69. self.model.description = self.model.desc
  70. }
  71. } else {
  72. this.model = {}
  73. self.formAction = 0
  74. // self.$nextTick(() => {
  75. // self.$refs.form.resetFields();
  76. // self.formAction = 0;
  77. // })
  78. }
  79. },
  80. uploadTrigger() {
  81. this.$refs.upFilesDataRef.click()
  82. },
  83. // 上传科研数据的事件
  84. onDataFileSelect(e) {
  85. // if (this.$refs.upFilesDataRef.value.indexOf('.txt') != -1) return this.$message('不支持.txt格式的文件 ')
  86. var f = e.target.files || e.dataTransfer.files
  87. if (!f.length) return
  88. this.filesData = f[0]
  89. console.log(this.filesData)
  90. // 上传进度
  91. var _this = this
  92. this.$refs.upFilesDataRef.onchange = function() {
  93. var fr = new FileReader()
  94. fr.readAsDataURL(this.files[0])
  95. var total = this.files[0].size
  96. fr.onprogress = function(ev) {
  97. _this.percentage = parseInt((ev.loaded / total) * 100) + '%'
  98. console.log(_this.percentage)
  99. if (_this.percentage == '100%') {
  100. _this.$set(_this.model, 'file', _this.filesData.name)
  101. }
  102. }
  103. }
  104. this.$refs.upFilesDataRef.onchange()
  105. },
  106. closeDialog() {
  107. this.$refs.form.resetFields()
  108. this.filesData = ''
  109. this.$refs.upFilesDataRef.value = ''
  110. },
  111. dataFormSubmit() {
  112. let self = this
  113. self.$refs['form'].validate(async valid => {
  114. if (valid) {
  115. var formdata = new FormData()
  116. // form.append('name', this.model.name)
  117. // form.append('key', this.model.name)
  118. // form.append('description', this.model.name)
  119. // form.append('category', this.model.name)
  120. if (!this.model.file) return this.$message.error('请检查您的文件!')
  121. formdata.append('file', this.filesData)
  122. console.log(this.filesData)
  123. delete this.model.file
  124. var obj = {
  125. url: this.$url.processinst.exportFile,
  126. data: this.model
  127. }
  128. const {data:res} = await this.common.postRequestHybid(obj, formdata)
  129. console.log(res)
  130. if(res.code!==1) return this.$message.error('导入失败!')
  131. this.$emit('change')
  132. // let model = self.model
  133. // var obj = {
  134. // url: this.$url.workflowdef.add,
  135. // data: self.model
  136. // }
  137. // this.common.httpPost(obj, success)
  138. // function success(data) {
  139. // self.$notify.success({
  140. // title: '',
  141. // message: '操作成功!'
  142. // })
  143. // self.$parent.editFormVisible = false
  144. // self.$parent.doSearch(1)
  145. // }
  146. } else {
  147. self.$notify.error({
  148. title: '错误',
  149. message: '系统输入验证失败!'
  150. })
  151. return false
  152. }
  153. })
  154. }
  155. }
  156. }
  157. </script>
  158. <style>
  159. .exportFile input {
  160. border: none !important;
  161. /* width: 75px;
  162. height: 25px;
  163. opacity: 0;
  164. filter: alpha(opacity=0);
  165. background-color: lawngreen; */
  166. }
  167. .btnUpfileBox {
  168. display: flex;
  169. }
  170. .btnUpfileBox .filename {
  171. width: 300px;
  172. margin-right: 10px;
  173. }
  174. .btnUpfileBox .btnUpfile {
  175. width: 100px;
  176. height: 100%;
  177. background-color: #409eff;
  178. }
  179. .btnUpfileBox span {
  180. display: inline-block;
  181. width: 100%;
  182. text-align: right;
  183. }
  184. </style>