mixedSheetEdit.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="customSheet-wrap">
  3. <div class="wrap-top">
  4. <ul class="form-ul">
  5. <li>
  6. <el-input
  7. v-model="sheetForm.name"
  8. :placeholder="$t('OnlineExcelPage.please_table_name_ipt')"
  9. style="width:220px"
  10. clearable>
  11. </el-input>
  12. </li>
  13. <li>
  14. <el-cascader
  15. v-model="sheetForm.classify"
  16. :options="classifyArr"
  17. style="width:220px;"
  18. :props="{
  19. label: 'ExcelClassifyName',
  20. value: 'ExcelClassifyId',
  21. children: 'Children',
  22. emitPath: false,
  23. checkStrictly: true
  24. }"
  25. clearable
  26. :placeholder="$t('OnlineExcelPage.select_table_category')"
  27. />
  28. </li>
  29. <li>
  30. {{$t('OnlineExcelPage.table_explaination_text')}}
  31. <el-tooltip
  32. effect="dark"
  33. >
  34. <div
  35. slot="content"
  36. v-html="rules"
  37. style="line-height: 20px;width:350px"
  38. ></div>
  39. <i class="el-icon-question" />
  40. </el-tooltip>
  41. </li>
  42. </ul>
  43. <div>
  44. <span v-if="updateTime" style="color:#999999 ;">{{$t('OnlineExcelPage.recent_save_time_info')}}{{updateTime}}</span>
  45. <el-button type="primary" size="medium" :loading="updating" @click="updateHandle" style="margin-left:10px" icon="el-icon-refresh-right">{{updating?$t('ETable.Btn.renewing_btn'):$t('ETable.Btn.renew_btn')}}</el-button>
  46. <el-button type="primary" size="medium" @click="saveSheetHandle" style="margin-left:10px" v-if="hasPermission">{{$t('ETable.Btn.save_btn')}}</el-button>
  47. <el-button type="primary" size="medium" plain @click="backHandle">{{$t('ETable.Btn.back_btn')}}</el-button>
  48. </div>
  49. </div>
  50. <MixedTable @autoSave="autoSaveFun"
  51. ref="mixedTableRef"
  52. />
  53. </div>
  54. </template>
  55. <script>
  56. import * as sheetInterface from '@/api/modules/sheetApi.js';
  57. import { dataBaseInterface } from 'api/api.js';
  58. import selectTarget from '@/views/chartRelevance_manage/components/selectTarget.vue';
  59. import MixedTable from './components/MixedTable.vue'
  60. import html2canvas from 'html2canvas';
  61. export default {
  62. components: { selectTarget,MixedTable },
  63. beforeRouteEnter(to, from, next) {
  64. if(to.query.id){
  65. to.matched[1].name=`编辑表格`
  66. }else{
  67. to.matched[1].name='添加表格'
  68. }
  69. next()
  70. },
  71. watch:{
  72. sheetForm:{
  73. handler(newVal){
  74. // console.log(newVal,'newVal','newVal');
  75. if(this.sheetInit && this.sheetId) this.autoSaveFun()
  76. },
  77. deep:true
  78. }
  79. },
  80. computed:{
  81. hasPermission(){
  82. // console.log(this.sheetButton,'sheetButton');
  83. return this.sheetButton?
  84. this.permissionBtn.isShowBtn('etaTablePermission','etaTable_customize_mix_save')&&this.sheetButton.OpButton:
  85. this.permissionBtn.isShowBtn('etaTablePermission','etaTable_customize_mix_save')
  86. },
  87. rules(){
  88. return this.$t('OnlineExcelPage.TableInstructionsText') ||''
  89. },
  90. sheetTypeOption(){
  91. return [
  92. { key: 1,label: this.$t('OnlineExcelPage.data_row_label')},
  93. { key: 2,label: this.$t('OnlineExcelPage.data_column_label')},
  94. ]
  95. }
  96. },
  97. // beforeRouteLeave(to,from,next){
  98. // if(to.path!='/addMixedSheet'){
  99. // this.markFinishStatus()
  100. // }
  101. // next()
  102. // },
  103. data() {
  104. return {
  105. sheetId: this.$route.query.id || '',
  106. classifyArr: [],
  107. sheetForm: {
  108. sheetType: 1
  109. },
  110. sheetButton:'',
  111. sheetInit:false,
  112. updateTime: '',
  113. isCanEdit:false,
  114. // 取消自动保存,比如返回的时候
  115. cancelAutoSave:false,
  116. updating:false,//更新状态
  117. }
  118. },
  119. methods: {
  120. backHandle() {
  121. this.cancelAutoSave=true
  122. this.$router.back()
  123. },
  124. /* 获取表格详情 */
  125. async getDetail(type='init') {
  126. if(!this.sheetId) return
  127. const res = await sheetInterface.sheetDetail({
  128. ExcelInfoId: Number(this.sheetId)
  129. })
  130. if(type==='refresh'){
  131. this.updating=false
  132. }
  133. if(res.Ret !== 200) return
  134. this.isCanEdit = res.Data.CanEdit
  135. if(!res.Data.CanEdit){
  136. this.$message.warning(`${res.Data.Editor}${this.$t('OnlineExcelPage.currently_editing_msg') }`)
  137. setTimeout(()=>{
  138. this.backHandle()
  139. },2000)
  140. return
  141. }
  142. const { ExcelName,ExcelClassifyId,TableData,ModifyTime,Button } = res.Data;
  143. this.sheetButton=Button
  144. this.sheetForm = {
  145. name: ExcelName,
  146. classify: ExcelClassifyId
  147. }
  148. this.$nextTick(()=>{
  149. this.sheetInit=true
  150. })
  151. this.updateTime = this.$moment(ModifyTime).format('YYYY-MM-DD HH:mm:ss')
  152. this.$refs.mixedTableRef.initData(TableData);
  153. type==='refresh' && this.$message.success(this.$t('OnlineExcelPage.table_data_update_msg') )
  154. },
  155. /* 获取分类 */
  156. getClassify() {
  157. sheetInterface.excelClassifyOne({Source: 3}).then(res => {
  158. if(res.Ret !==200) return
  159. this.classifyArr = res.Data.AllNodes || [];
  160. })
  161. },
  162. autoSaveFun:_.debounce(async function(){
  163. if(!this.sheetId || this.cancelAutoSave) return
  164. const { name,classify,sheetType } = this.sheetForm;
  165. if(!name || !classify) return this.$message.warning(name ? this.$t('OnlineExcelPage.select_table_category') : this.$t('OnlineExcelPage.please_table_name_ipt') )
  166. let checkAllEmpty = this.$refs.mixedTableRef.config.data.flat(1).some(_ => _.ShowValue);
  167. if(!checkAllEmpty) return this.$message.warning(this.$t('OnlineExcelPage.input_content_msg') )
  168. let params = {
  169. ExcelName: name,
  170. ExcelType: 1,
  171. ExcelClassifyId: classify,
  172. ExcelImage:'',
  173. Source: 3,
  174. TableData: this.$refs.mixedTableRef.getSaveParams()
  175. };
  176. console.log("自动保存");
  177. const res = await sheetInterface.sheetEdit({ ExcelInfoId: Number(this.sheetId),...params })
  178. if(res.Ret !==200) return
  179. if(res.Data.Status==1){
  180. this.$message.warning(res.Data.Msg)
  181. setTimeout(()=>{
  182. this.backHandle()
  183. },1000)
  184. return
  185. }
  186. this.updateTime = this.$moment().format('YYYY-MM-DD HH:mm:ss')
  187. },1500),
  188. /* 保存表格 */
  189. saveSheetHandle: _.debounce(async function() {
  190. const { name,classify,sheetType } = this.sheetForm;
  191. if(!name || !classify) return this.$message.warning(name ? this.$t('OnlineExcelPage.select_table_category') : this.$t('OnlineExcelPage.please_table_name_ipt') )
  192. let checkAllEmpty = this.$refs.mixedTableRef.config.data.flat(1).some(_ => _.ShowValue);
  193. if(!checkAllEmpty) return this.$message.warning(this.$t('OnlineExcelPage.input_content_msg') )
  194. let canvas = await html2canvas(document.getElementsByClassName('table')[0],{
  195. scale:2,
  196. useCORS: true,
  197. backgroundColor:null,
  198. imageTimeout:0,
  199. allowTaint:true,
  200. })
  201. let imagesrc = canvas.toDataURL('image/png');
  202. const formData = new FormData();
  203. formData.append('Image',imagesrc);
  204. const { Data } = await dataBaseInterface.uploadImg(formData)
  205. let params = {
  206. ExcelName: name,
  207. ExcelType: 1,
  208. ExcelClassifyId: classify,
  209. ExcelImage: Data.ResourceUrl,
  210. Source: 3,
  211. TableData: this.$refs.mixedTableRef.getSaveParams()
  212. };
  213. let isAdd = this.sheetId?false:true
  214. const res = this.sheetId
  215. ? await sheetInterface.sheetEdit({ ExcelInfoId: Number(this.sheetId),...params })
  216. : await sheetInterface.sheetAdd(params)
  217. if(res.Ret !==200) return
  218. if(res.Data.Status==1){
  219. this.$message.warning(res.Data.Msg)
  220. setTimeout(()=>{
  221. this.backHandle()
  222. },1000)
  223. return
  224. }
  225. this.updateTime = this.$moment().format('YYYY-MM-DD HH:mm:ss')
  226. this.sheetId = this.sheetId || res.Data.ExcelInfoId;
  227. this.$message.success(this.$t('MsgPrompt.saved_msg') )
  228. isAdd && this.$router.replace({path:'/addMixedSheet',query:{id:this.sheetId}})
  229. },300),
  230. //更新
  231. updateHandle(){
  232. if(this.updating) return
  233. this.updating=true
  234. this.sheetInit=false
  235. this.getDetail('refresh')
  236. },
  237. // markFinishStatus(){
  238. // if((!this.sheetId) || (!this.isCanEdit)) return
  239. // sheetInterface.markSheetEditStatus({ExcelInfoId: +this.sheetId,Status:2}).then(res=>{
  240. // if(res.Ret != 200) return
  241. // })
  242. // }
  243. },
  244. created() {
  245. this.getClassify();
  246. this.getDetail();
  247. },
  248. // mounted(){
  249. // window.addEventListener('beforeunload',this.markFinishStatus)
  250. // },
  251. // beforeDestroy(){
  252. // window.removeEventListener('beforeunload',this.markFinishStatus)
  253. // }
  254. }
  255. </script>
  256. <style scoped lang="scss">
  257. *{ box-sizing: border-box; }
  258. .customSheet-wrap {
  259. min-width: 1070px;
  260. min-height: calc(100vh - 120px);
  261. .wrap-top {
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. margin-bottom: 20px;
  266. padding: 20px;
  267. background: #fff;
  268. border: 1px solid #ececec;
  269. border-radius: 4px;
  270. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  271. display: flex;
  272. z-index: 1;
  273. .form-ul {
  274. flex: 1;
  275. display: flex;
  276. align-items: center;
  277. li {
  278. margin: 0 10px;
  279. &:first-child {
  280. padding-top: 0;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. </style>