mixedSheetEdit.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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="请输入表格名称"
  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="请选择表格分类"
  27. />
  28. </li>
  29. <li>
  30. 表格说明
  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 ;">最近保存时间:{{updateTime}}</span>
  45. <el-button type="primary" size="medium" @click="()=>{ sheetInit=false;getDetail('refresh')}" style="margin-left:10px" icon="el-icon-refresh-right">更新</el-button>
  46. <el-button type="primary" size="medium" @click="saveSheetHandle" style="margin-left:10px" v-if="hasPermission">保存</el-button>
  47. <el-button type="primary" size="medium" plain @click="backHandle">返回</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. },
  88. // beforeRouteLeave(to,from,next){
  89. // if(to.path!='/addMixedSheet'){
  90. // this.markFinishStatus()
  91. // }
  92. // next()
  93. // },
  94. data() {
  95. return {
  96. sheetId: this.$route.query.id || '',
  97. classifyArr: [],
  98. rules: `表格说明:<br>
  99. 1、手动输入:单击每个单元格可直接输入文本、数字、日期(格式示例:2023-05-23)<br>
  100. 2、根据表格中日期选择指标值:在弹窗中搜索并选择指标,默认选择指标最新日期,可插入指标值,随着指标更新;也支持选择指标后,在表格中选择或输入一个日期,则插入该指标在选定日期的值。<br>
  101. 3、导入日期:导入系统或指标相关的日期,可进一步进行日期变换,跟随系统日期或指标日期更新。<br>
  102. 4、日期计算:对表格中日期进行计算。<br>
  103. 5、指标计算:选择指标进行计算,插入指标计算值。`,
  104. sheetForm: {
  105. sheetType: 1
  106. },
  107. sheetButton:'',
  108. sheetInit:false,
  109. sheetTypeOption: [
  110. { key: 1,label: '指标列+日期行' },
  111. { key: 2,label: '指标行+日期列' },
  112. ],
  113. updateTime: '',
  114. isCanEdit:false,
  115. // 取消自动保存,比如返回的时候
  116. cancelAutoSave: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(res.Ret !== 200) return
  131. this.isCanEdit = res.Data.CanEdit
  132. if(!res.Data.CanEdit){
  133. this.$message.warning(`${res.Data.Editor}正在编辑中`)
  134. setTimeout(()=>{
  135. this.backHandle()
  136. },2000)
  137. return
  138. }
  139. const { ExcelName,ExcelClassifyId,TableData,ModifyTime,Button } = res.Data;
  140. this.sheetButton=Button
  141. this.sheetForm = {
  142. name: ExcelName,
  143. classify: ExcelClassifyId
  144. }
  145. this.$nextTick(()=>{
  146. this.sheetInit=true
  147. })
  148. this.updateTime = this.$moment(ModifyTime).format('YYYY-MM-DD HH:mm:ss')
  149. this.$refs.mixedTableRef.initData(TableData);
  150. type==='refresh' && this.$message.success('表格数据已更新')
  151. },
  152. /* 获取分类 */
  153. getClassify() {
  154. sheetInterface.excelClassifyOne({Source: 3}).then(res => {
  155. if(res.Ret !==200) return
  156. this.classifyArr = res.Data.AllNodes || [];
  157. })
  158. },
  159. autoSaveFun:_.debounce(async function(){
  160. if(!this.sheetId || this.cancelAutoSave) return
  161. const { name,classify,sheetType } = this.sheetForm;
  162. if(!name || !classify) return this.$message.warning(name ? '请选择表格分类' : '请输入表格名称')
  163. let checkAllEmpty = this.$refs.mixedTableRef.config.data.flat(1).some(_ => _.ShowValue);
  164. if(!checkAllEmpty) return this.$message.warning('请输入表格内容')
  165. let params = {
  166. ExcelName: name,
  167. ExcelType: 1,
  168. ExcelClassifyId: classify,
  169. ExcelImage:'',
  170. Source: 3,
  171. TableData: this.$refs.mixedTableRef.getSaveParams()
  172. };
  173. console.log("自动保存");
  174. const res = await sheetInterface.sheetEdit({ ExcelInfoId: Number(this.sheetId),...params })
  175. if(res.Ret !==200) return
  176. if(res.Data.Status==1){
  177. this.$message.warning(res.Data.Msg)
  178. setTimeout(()=>{
  179. this.backHandle()
  180. },1000)
  181. return
  182. }
  183. this.updateTime = this.$moment().format('YYYY-MM-DD HH:mm:ss')
  184. },1500),
  185. /* 保存表格 */
  186. saveSheetHandle: _.debounce(async function() {
  187. const { name,classify,sheetType } = this.sheetForm;
  188. if(!name || !classify) return this.$message.warning(name ? '请选择表格分类' : '请输入表格名称')
  189. let checkAllEmpty = this.$refs.mixedTableRef.config.data.flat(1).some(_ => _.ShowValue);
  190. if(!checkAllEmpty) return this.$message.warning('请输入表格内容')
  191. let canvas = await html2canvas(document.getElementsByClassName('table')[0],{
  192. scale:2,
  193. useCORS: true,
  194. backgroundColor:null,
  195. imageTimeout:0,
  196. allowTaint:true,
  197. })
  198. let imagesrc = canvas.toDataURL('image/png');
  199. const formData = new FormData();
  200. formData.append('Image',imagesrc);
  201. const { Data } = await dataBaseInterface.uploadImg(formData)
  202. let params = {
  203. ExcelName: name,
  204. ExcelType: 1,
  205. ExcelClassifyId: classify,
  206. ExcelImage: Data.ResourceUrl,
  207. Source: 3,
  208. TableData: this.$refs.mixedTableRef.getSaveParams()
  209. };
  210. let isAdd = this.sheetId?false:true
  211. const res = this.sheetId
  212. ? await sheetInterface.sheetEdit({ ExcelInfoId: Number(this.sheetId),...params })
  213. : await sheetInterface.sheetAdd(params)
  214. if(res.Ret !==200) return
  215. if(res.Data.Status==1){
  216. this.$message.warning(res.Data.Msg)
  217. setTimeout(()=>{
  218. this.backHandle()
  219. },1000)
  220. return
  221. }
  222. this.updateTime = this.$moment().format('YYYY-MM-DD HH:mm:ss')
  223. this.sheetId = this.sheetId || res.Data.ExcelInfoId;
  224. this.$message.success('保存成功')
  225. isAdd && this.$router.replace({path:'/addMixedSheet',query:{id:this.sheetId}})
  226. },300),
  227. // markFinishStatus(){
  228. // if((!this.sheetId) || (!this.isCanEdit)) return
  229. // sheetInterface.markSheetEditStatus({ExcelInfoId: +this.sheetId,Status:2}).then(res=>{
  230. // if(res.Ret != 200) return
  231. // })
  232. // }
  233. },
  234. created() {
  235. this.getClassify();
  236. this.getDetail();
  237. },
  238. // mounted(){
  239. // window.addEventListener('beforeunload',this.markFinishStatus)
  240. // },
  241. // beforeDestroy(){
  242. // window.removeEventListener('beforeunload',this.markFinishStatus)
  243. // }
  244. }
  245. </script>
  246. <style scoped lang="scss">
  247. *{ box-sizing: border-box; }
  248. .customSheet-wrap {
  249. min-width: 1070px;
  250. min-height: calc(100vh - 120px);
  251. .wrap-top {
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: center;
  255. margin-bottom: 20px;
  256. padding: 20px;
  257. background: #fff;
  258. border: 1px solid #ececec;
  259. border-radius: 4px;
  260. box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
  261. display: flex;
  262. z-index: 1;
  263. .form-ul {
  264. flex: 1;
  265. display: flex;
  266. align-items: center;
  267. li {
  268. margin: 0 10px;
  269. &:first-child {
  270. padding-top: 0;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. </style>