HeaderEdit.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <header class="header">
  3. <button class="reset-btn" @click="goback"><i class="el-icon-arrow-left"></i>{{title || '返回作品'}}</button>
  4. <div class="tools">
  5. <div class="next_return">
  6. <div class="return" title="撤销" @click="revocation" :style="`opacity:${operationList.length>1?'1':'.3'}`">
  7. <img class="retutn_icon" src="../assets/images/button_return.png" alt="">
  8. <span>撤销</span>
  9. </div>
  10. <div class="return" title="恢复" @click="recover" :style="`opacity:${nextList.length>0?'1':'.3'}`">
  11. <img class="retutn_icon" src="../assets/images/button_next.png" alt="">
  12. <span>恢复</span>
  13. </div>
  14. <div class="return" title="分享设置" @click="shareSetting">
  15. <img class="retutn_icon" src="../assets/images/share_setting_edit_nor.png" alt="">
  16. <span>分享设置</span>
  17. </div>
  18. <div class="return" title="保存" @click="save">
  19. <img class="retutn_icon" src="../assets/images/save_edit_nor.png" alt="">
  20. <span>保存</span>
  21. </div>
  22. </div>
  23. </div>
  24. <!-- <div class="next_return">
  25. <span class="return" title="撤销" @click="revocation" :style="`opacity:${operationList.length>1?'1':'.3'}`"></span>
  26. <span class="next" title="恢复" @click="recover" :style="`opacity:${nextList.length>0?'1':'.3'}`"></span>
  27. </div>
  28. <el-button @click="grid" class="preview " type="primary" style="margin-left: 50px;">网格参考线</el-button>
  29. <div class="right-panel">
  30. <el-button @click="deploy" class="preview" type="primary" :loading="loading">预览</el-button> -->
  31. <!--<el-button @click="psd"-->
  32. <!--class="preview"-->
  33. <!--type="primary"-->
  34. <!--:loading="loading" style="margin-right: 20px">PSD导入</el-button>-->
  35. <!--<el-upload-->
  36. <!--class="upload-demo"-->
  37. <!--:action="`${appConst}/api/pages/psd`"-->
  38. <!--accept="A/.psd"-->
  39. <!--:on-change="uploadFn">-->
  40. <!--<el-button size="small" type="primary">psd文件导入</el-button>-->
  41. <!--<div slot="tip" class="el-upload__tip">只能上传psd文件</div>-->
  42. <!--</el-upload>-->
  43. <!-- <form id="upload" enctype='multipart/form-data'>
  44. <input type="hidden" id="itemId" />
  45. <input type="file" id="psdFile" name="image" @change="uploadFn">
  46. </form>
  47. </div> -->
  48. <!-- 分享设置 -->
  49. <ShareSetting v-show="isShareSetting" :close="closeShare" :shareModel="shareModel"></ShareSetting>
  50. </header>
  51. </template>
  52. <script>
  53. import tools from "../util/tools";
  54. import api from "../api/editor";
  55. import ShareSetting from "./ShareSetting";
  56. var time = null;
  57. export default {
  58. props: {
  59. goback: Function,
  60. save: Function,
  61. title: "",
  62. shareModel: ""
  63. },
  64. components: {
  65. ShareSetting
  66. },
  67. data() {
  68. return {
  69. loading: false,
  70. operationList: [],
  71. nextList: [],
  72. isShareSetting: false
  73. };
  74. },
  75. beforeCreate() {
  76. window.revocationFlag = false;
  77. },
  78. destroyed() {
  79. this.operationList = [];
  80. this.nextList = [];
  81. },
  82. mounted: function() {
  83. var that = this;
  84. /*var fn=function(e) {
  85. if (90 == e.keyCode && e.ctrlKey)
  86. {
  87. that.revocation()
  88. }
  89. if(88 == e.keyCode && e.ctrlKey){
  90. that.recover()
  91. }
  92. }
  93. document.removeEventListener("keydown",fn)
  94. document.addEventListener("keydown",fn)*/
  95. },
  96. computed: {
  97. obj: function() {
  98. return JSON.stringify(this.$store.state.editor.editorPage);
  99. },
  100. operationFlag: function() {
  101. return this.$store.state.user.operationFlag;
  102. }
  103. },
  104. watch: {
  105. obj: function(v) {
  106. var that = this;
  107. if (!revocationFlag) {
  108. if (that.operationList.length == 0) {
  109. that.operationList.push(v);
  110. }
  111. return;
  112. }
  113. window.hasSaveFlag = false;
  114. clearTimeout(time);
  115. time = setTimeout(function() {
  116. if (that.operationFlag) {
  117. that.nextList = [];
  118. that.operationList.push(v);
  119. }
  120. }, 500);
  121. }
  122. },
  123. methods: {
  124. notempty(arrays) {
  125. for (var i = 0; i < arrays.length; i++) {
  126. if (
  127. arrays[i] == "" ||
  128. arrays[i] == null ||
  129. typeof arrays[i] == "undefined"
  130. ) {
  131. arrays.splice(i, 1);
  132. i--;
  133. } else {
  134. this.$store.dispatch("addElement", arrays[i]);
  135. }
  136. }
  137. return arrays;
  138. },
  139. uploadFn(e) {
  140. var that = this;
  141. var form = document.getElementById("upload"),
  142. formData = new FormData(form);
  143. document.getElementById("itemId").innerText = this.$route.query.itemId;
  144. // this.$store.dispatch('uploadPsd', formData)
  145. const loading = this.$loading({
  146. lock: true,
  147. text: "psd解析中...",
  148. spinner: "el-icon-loading",
  149. background: "rgba(0, 0, 0, 0.7)"
  150. });
  151. try {
  152. api
  153. .uploadPsd(formData)
  154. .then(function(res) {
  155. loading.close();
  156. var res = res;
  157. that.$store.state.editor.editorPage.elements = [];
  158. that.notempty(res["pages"][0].elements);
  159. // that.$store.state.editor.editorPage.elements=res['pages'][0].elements
  160. that.$store.state.editor.editorTheme.title = res["title"];
  161. that.$store.state.editor.editorTheme.description =
  162. res["description"];
  163. that.$store.state.editor.editorTheme.canvasHeight = Number(
  164. res["canvasHeight"]
  165. );
  166. that.$store.state.editor.editorTheme.canvasWidth =
  167. res["canvasWidth"];
  168. })
  169. .catch(function(err) {
  170. loading.close();
  171. that.$message.error("psd文件解析失败");
  172. });
  173. } catch (e) {
  174. loading.close();
  175. that.$message.error("psd文件解析失败");
  176. }
  177. form.reset();
  178. },
  179. revocation() {
  180. if (this.operationList.length < 2) {
  181. return false;
  182. }
  183. if (!revocationFlag) {
  184. return false;
  185. }
  186. revocationFlag = false;
  187. var str = this.operationList.splice(this.operationList.length - 1, 1);
  188. this.nextList.push(str[0]);
  189. this.$store.state.editor.editorPage.elements = JSON.parse(
  190. this.operationList[this.operationList.length - 1]
  191. ).elements;
  192. setTimeout(function() {
  193. revocationFlag = true;
  194. }, 400);
  195. }, //撤销
  196. recover() {
  197. if (this.nextList.length == 0) {
  198. return false;
  199. }
  200. if (!revocationFlag) {
  201. return false;
  202. }
  203. revocationFlag = false;
  204. this.$store.state.editor.editorPage.elements = JSON.parse(
  205. this.nextList[this.nextList.length - 1]
  206. ).elements;
  207. this.operationList.push(
  208. this.nextList.splice(this.nextList.length - 1, 1)[0]
  209. );
  210. setTimeout(function() {
  211. revocationFlag = true;
  212. }, 400);
  213. }, //恢复
  214. deploy() {
  215. // this.loading = true
  216. /*this.$store.dispatch('saveTheme', tools.vue2json(this.$store.state.editor.editorTheme)).then(() => {
  217. // setTimeout(() => {
  218. // this.$emit('saveThemeSuccess')
  219. // this.loading = false
  220. // }, 1000)
  221. this.$emit('saveThemeSuccess')
  222. this.loading = false
  223. })*/
  224. if (!window.hasSaveFlag) {
  225. this.$confirm("您确定不保存直接预览吗?", "提示", {
  226. confirmButtonText: "确定",
  227. cancelButtonText: "取消",
  228. type: "warning"
  229. })
  230. .then(() => {
  231. window.hasSaveFlag = false;
  232. this.$emit("saveThemeSuccess");
  233. })
  234. .catch(() => {});
  235. } else {
  236. this.$emit("saveThemeSuccess");
  237. }
  238. },
  239. grid() {
  240. //网格
  241. if (!this.$store.state.editor.gridTempField) {
  242. this.$store.state.editor.gridTempField = true;
  243. } else {
  244. this.$store.state.editor.gridTempField = false;
  245. }
  246. },
  247. psd() {
  248. var that = this;
  249. axios.get("../../static/json.json").then(function(res) {
  250. var res = res.data;
  251. that.$store.state.editor.editorTheme.title = res["title"];
  252. that.$store.state.editor.editorTheme.description = res["description"];
  253. that.$store.state.editor.editorTheme.canvasHeight = res["canvasHeight"];
  254. that.$store.state.editor.editorTheme.canvasWidth = res["canvasWidth"];
  255. that.$store.state.editor.editorPage.elements = res["pages"][0].elements;
  256. });
  257. },
  258. shareSetting() {
  259. this.isShareSetting = true;
  260. },
  261. closeShare() {
  262. this.isShareSetting = false;
  263. },
  264. save() {}
  265. }
  266. };
  267. </script>
  268. <style lang="less" scoped>
  269. .header {
  270. height: 60px;
  271. background-color: #fff;
  272. color: #646b81;
  273. margin-top: 60px;
  274. position: relative;
  275. display: flex;
  276. flex-direction: row;
  277. .reset-btn {
  278. position: absolute;
  279. left: 0px;
  280. top: 0px;
  281. height: 100%;
  282. padding: 0 50px;
  283. cursor: pointer;
  284. }
  285. .el-icon-arrow-left {
  286. margin-right: 10px;
  287. }
  288. .right-panel {
  289. float: right;
  290. height: 100%;
  291. width: 100px;
  292. display: flex;
  293. align-items: center;
  294. padding-right: 15px;
  295. flex-direction: row-reverse;
  296. }
  297. .tools {
  298. width: 100%;
  299. height: 60px;
  300. .next_return {
  301. display: flex;
  302. flex-direction: row;
  303. align-items: center;
  304. justify-content: center;
  305. height: 100%;
  306. .return {
  307. display: flex;
  308. flex-direction: column;
  309. align-items: center;
  310. justify-content: center;
  311. padding-left: 16px;
  312. padding-right: 16px;
  313. font-size: 16px;
  314. color: rgba(100, 107, 129, 1);
  315. .retutn_icon {
  316. width: 24px;
  317. height: 21px;
  318. margin-bottom: 5px;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. </style>