index.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. <template>
  2. <div class="editor">
  3. <!-- 头部 -->
  4. <HeaderMain></HeaderMain>
  5. <HeaderEdit :title="title" :goback="dialogSave" :save="save" @saveThemeSuccess="showPreView=true" />
  6. <!-- 内容区域 -->
  7. <section class="section">
  8. <!-- 左侧图层 -->
  9. <Overview class="overview" :testcaseId="testcaseId" />
  10. <!-- 编辑区域 -->
  11. <div class="container" id="h5editor">
  12. <elab-canvas v-show="animatedNameGlobal!=''" :width="750" :height="1334"
  13. :cstyle="`height:1334px;width:750px;position: absolute;z-index:99999; pointer-events:none`"
  14. :background="'transparent'" :type="animatedNameGlobal"></elab-canvas>
  15. <elab-background-canvas v-if="animatedNameBackgroundGlobal!=''" :width="canvasWidth" :height="(canvasHeight)"
  16. :cstyle="`position: absolute;z-index:1; pointer-events:none`" :background="'transparent'"
  17. :type="animatedNameBackgroundGlobal"></elab-background-canvas>
  18. <Page :isOverView="false" ref="page" id="canvasPage" :hideFoot="hideFoot" class="canvas"
  19. :elements="editorPage.elements" :editorElement="element" :animatedNameGlobal="animatedNameGlobal"
  20. :selectedElement="selectedElement"
  21. :style="{ width: 750 + 'px', height: 1334 + 'px',backgroundColor: bodyBackgroundColor }" />
  22. <div v-if="this.gridTempField" :style="{'background-image':'linear-gradient(90deg,rgba(204,204,204,0.3) 10%,transparent 0), linear-gradient(rgba(204,204,204,0.3) 10%,transparent 0)',
  23. 'background-size':'15px 15px', 'z-index':100000,width: '750px', height: '1334px'}"
  24. style="position: absolute;left: 0;top: 0;z-index: 9999;pointer-events: none"></div>
  25. </div>
  26. <!-- 属性设置 -->
  27. <div class="control-panel">
  28. <div class="funcs">
  29. <div class="tagPage">
  30. <div style="width:44px;height: 44px; margin-top: 20px;display: flex;justify-content: center"
  31. @click="togglePanel(1)" :class="{ active: panelState === 1 }">
  32. <img style="width:34px;height: 34px;" src="http://yun-image.elab-plus.com/images/dyb/new-text.png" alt="">
  33. </div>
  34. <div class="page-tag-btn-tip">创建文本</div>
  35. </div>
  36. <div class="tagPage">
  37. <div style="width:44px;height: 44px;display: flex;justify-content: center" @click="togglePanel(2)"
  38. :class="{ active: panelState === 2 }">
  39. <img style="width:34px;height: 34px;" src="http://yun-image.elab-plus.com/images/dyb/new-zhuangshi.png"
  40. alt="">
  41. </div>
  42. <div class="page-tag-btn-tip">装饰元素</div>
  43. </div>
  44. <div class="tagPage">
  45. <div style="width:44px;height: 44px;display: flex;justify-content: center" @click="togglePanel(3)"
  46. :class="{ active: panelState === 3 }">
  47. <img style="width:34px;height: 34px;" src="http://yun-image.elab-plus.com/images/dyb/new-lunbo.png"
  48. alt="">
  49. </div>
  50. <div class="page-tag-btn-tip">新建轮播</div>
  51. </div>
  52. <div class="tagPage">
  53. <div style="width:44px;height: 44px;display: flex;justify-content: center" @click="togglePanel(4)"
  54. :class="{ active: panelState === 4 }">
  55. <img style="width:34px;height: 34px;" src="http://yun-image.elab-plus.com/images/dyb/new-jiaohuanniu.png"
  56. alt="">
  57. </div>
  58. <div class="page-tag-btn-tip">交互按钮</div>
  59. </div>
  60. <el-tooltip v-show="false" effect="dark" content="保存" placement="left">
  61. <div style="width:44px;height: 44px;display: flex;justify-content: center" @click="save">
  62. <img style="width:34px;height: 34px;" src="http://yun-image.elab-plus.com/images/dyb/new-jiaohuanniu.png"
  63. alt="">
  64. </div>
  65. </el-tooltip>
  66. </div>
  67. <div class="wrapper custom-scrollbar">
  68. <!-- 设置背景 0 -->
  69. <div class="panel panel-bg">
  70. <div class="clearfix" v-if="panelTabState !== 1 && panelTabState !== 3">
  71. <div
  72. style="display: flex;flex-direction: row;justify-content: space-between; padding:23px;border-bottom: #E2E4EE solid 1px;">
  73. <div style="width:45%;
  74. height:28px;
  75. text-align: center;
  76. background:rgba(78,93,255,1);
  77. border-radius:14px;font-size:14px;
  78. font-family:MicrosoftYaHei;
  79. color:rgba(255,255,255,1);
  80. line-height:28px;" @click="cleanBG">移除背景</div>
  81. <div style="width:45%;height:28px;text-align: center;background:rgba(78,93,255,1);border-radius:14px;font-size:14px;
  82. font-family:MicrosoftYaHei;color:rgba(255,255,255,1);line-height:28px;"
  83. @click="panelTabState = 1">
  84. 更换背景</div>
  85. </div>
  86. <div
  87. style="display: flex;flex-direction: row;align-items: center;padding-left: 23px;border-bottom: #E2E4EE solid 1px;padding-top: 11px;padding-bottom: 11px;">
  88. <label style="font-size:12px;
  89. font-family:MicrosoftYaHei;
  90. color:rgba(51,51,51,1);
  91. margin-right: 10px;
  92. ">画布背景色</label>
  93. <el-color-picker v-model="bodyBackgroundColor" @change="bodyBackgroundColorChange" size="mini">
  94. </el-color-picker>
  95. </div>
  96. <div
  97. style="display: flex;flex-direction: row ;padding-left: 23px;padding-top: 12px;padding-bottom: 12px;border-bottom: #E2E4EE solid 1px;">
  98. <div style="display: flex;flex-direction: column;">
  99. <label style="font-size:12px;
  100. font-family:MicrosoftYaHei;
  101. color:rgba(51,51,51,1); margin-bottom: 6px;">画布宽度</label>
  102. <el-input-number v-model="canvasWidth" :disabled="true" size="small" style="width:110px;">
  103. </el-input-number>
  104. </div>
  105. <div style="display: flex;flex-direction: column; margin-left:45px">
  106. <label style="font-size:12px;
  107. font-family:MicrosoftYaHei;
  108. color:rgba(51,51,51,1); margin-bottom: 6px;">画布高度</label>
  109. <el-input-number v-model="canvasHeight" size="small" style="width:110px;">
  110. </el-input-number>
  111. </div>
  112. </div>
  113. <div class="clearfix" v-if="panelTabState !== 1 && panelTabState !== 3" style="border-bottom: #E2E4EE solid 1px; padding-top:010px;padding-bottom:2px;
  114. padding-left:23px;
  115. ">
  116. <label style="font-size:12px;
  117. font-family:MicrosoftYaHei; display:block;
  118. color:rgba(51,51,51,1);margin-bottom:10px;">屏飘动效</label>
  119. <div class="content" :xxx="`animatedNameGlobal`">
  120. <div
  121. style="display: inline-flex;overflow: hidden;text-align: center; cursor: pointer; margin-right:12px;"
  122. v-for="(item,index) in animateGlobalList">
  123. <div v-model="animatedNameGlobal" @click="checkGlobalAnimation(item)" :title="item.name" :style="{'background':'rgba(238,242,250,1)',
  124. 'border-radius':'12px', 'margin-bottom':'10px',
  125. 'border':'1px solid rgba(205,209,221,1)','font-size': '12px',
  126. color: animatedNameGlobal==item.id? 'white':'#999999','letter-spacing': 0,
  127. 'word-break':'keep-all',padding: '4px 13px','background': animatedNameGlobal===item.id? '#4E5DFF':'rgba(238,242,250,1)',
  128. 'border': animatedNameGlobal===item.id? '1px solid #4E5DFF':'1px solid rgba(205,209,221,1)',
  129. }">{{item.name}}</div>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="clearfix" v-if="panelTabState !== 1 && panelTabState !== 3" style="border-bottom: #E2E4EE solid 1px; padding-top:010px;padding-bottom:2px;
  134. padding-left:23px;">
  135. <label style="font-size:12px;
  136. font-family:MicrosoftYaHei; display:block;
  137. color:rgba(51,51,51,1);margin-bottom:10px;">背景动效</label>
  138. <div class="content" :xxx="`animatedNameBackgroundGlobal`">
  139. <div style="display: inline-flex;overflow: hidden;text-align: center; cursor: pointer"
  140. v-for="(item,index) in animateBackgroundGlobalList">
  141. <div v-model="animatedNameBackgroundGlobal" @click="checkBackgroundGlobalAnimation(item)"
  142. :title="item.name"
  143. :style="{'background':'rgba(238,242,250,1)', 'margin-right':'12px',
  144. 'border-radius':'12px', 'margin-bottom':'10px',
  145. 'border':'1px solid rgba(205,209,221,1)','font-size': '12px',
  146. color: animatedNameBackgroundGlobal==item.id? 'white':'#999999','letter-spacing': 0,
  147. 'word-break':'keep-all',padding: '4px 13px','background': animatedNameBackgroundGlobal===item.id? '#4E5DFF':'rgba(238,242,250,1)',
  148. 'border': animatedNameBackgroundGlobal===item.id? '1px solid #4E5DFF':'1px solid rgba(205,209,221,1)'}">{{item.name}}
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <div class="item" style="padding:10px 23px;">
  154. <label style="font-size:12px;
  155. font-family:MicrosoftYaHei;
  156. color:rgba(51,51,51,1);">背景音乐</label>
  157. <div class="content">
  158. <AudioPanel class="ele"></AudioPanel>
  159. </div>
  160. </div>
  161. </div>
  162. <!--<div class="clearfix">
  163. <label>设置作品信息</label>
  164. <div class="content">
  165. <el-input
  166. placeholder="请输入标题"
  167. v-model="title"
  168. clearable>
  169. </el-input>
  170. </div>
  171. <div class="content">
  172. <el-input
  173. placeholder="请输入描述"
  174. v-model="description"
  175. clearable>
  176. </el-input>
  177. </div>
  178. </div>-->
  179. <div class="clearfix" v-if="panelTabState === 1">
  180. <ImgPanel :selectedImg="addBG" />
  181. </div>
  182. <div class="clearfix" v-if="panelTabState === 3">
  183. <div style="margin-top: 5px; height:100%;vertical-align: middle;padding-right:10px">
  184. <div style="display: inline-flex; overflow: hidden;">
  185. <div style="font-size: 14px;color: #999999;letter-spacing: 0; word-break:keep-all;width:100%">
  186. 组合对齐布局
  187. </div>
  188. </div>
  189. <div style="margin-top: 10px">
  190. <div style="display: inline-flex; overflow: hidden;width: 14%; cursor: pointer; text-align: center">
  191. <div @click="toLeft" title="左对齐"
  192. :style="{'font-size': '12px','letter-spacing': 0, 'word-break':'keep-all','text-align':'center','width':'100%'}">
  193. <img src="http://yun-image.elab-plus.com/images/tfb/icon_left2.png" width="20" height="20" />
  194. </div>
  195. </div>
  196. <div title="水平居中对齐"
  197. style="display: inline-flex; overflow: hidden;width: 14%; cursor: pointer;text-align: center"
  198. @click="toCenter">
  199. <div
  200. :style="{'font-size': '12px','letter-spacing': 0, 'word-break':'keep-all','text-align':'center','width':'100%'}">
  201. <img src="http://yun-image.elab-plus.com/images/tfb/horizontal_center.png" width="20"
  202. height="20" />
  203. </div>
  204. </div>
  205. <div title="右对齐" style="display: inline-flex;cursor: pointer;width: 14%; text-align: center"
  206. @click="toRight">
  207. <div
  208. :style="{'font-size': '12px','letter-spacing': 0, 'word-break':'keep-all','text-align':'center','width':'100%'}">
  209. <img src="http://yun-image.elab-plus.com/images/tfb/icon_right2.png" width="20" height="20" />
  210. </div>
  211. </div>
  212. <div style="display: inline-flex; overflow: hidden;width: 14%; cursor: pointer; text-align: center">
  213. <div @click="toTop" title="上对齐"
  214. :style="{'font-size': '12px','letter-spacing': 0, 'word-break':'keep-all','text-align':'center','width':'100%'}">
  215. <img src="http://yun-image.elab-plus.com/images/tfb/icon_top.png" width="20" height="20" />
  216. </div>
  217. </div>
  218. <div title="垂直居中对齐"
  219. style="display: inline-flex; overflow: hidden;width: 14%; cursor: pointer;text-align: center"
  220. @click="toVertialCenter">
  221. <div
  222. :style="{'font-size': '12px','letter-spacing': 0, 'word-break':'keep-all','text-align':'center','width':'100%'}">
  223. <img src="http://yun-image.elab-plus.com/images/tfb/vertical_center.png" width="20" height="20" />
  224. </div>
  225. </div>
  226. <div title="下对齐" style="display: inline-flex;cursor: pointer;width: 14%; text-align: center"
  227. @click="toBottom">
  228. <div
  229. :style="{'font-size': '12px','letter-spacing': 0, 'word-break':'keep-all','text-align':'center','width':'100%'}">
  230. <img src="http://yun-image.elab-plus.com/images/tfb/icon_down.png" width="20" height="20" />
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. <!-- 添加文字 1 -->
  238. <div class="panel panel-text" v-show="panelState === 1">
  239. <div class="btn" @click="addTextElement('title')" style="font-size: 32px; font-weight: bold;">插入标题</div>
  240. <div class="btn" @click="addTextElement('plain')">插入文本</div>
  241. <div class="btn" @click="addTextElement('frame')">插入方框</div>
  242. </div>
  243. <!-- 添加元素 2 -->
  244. <div class="panel panel-element clearfix" v-show="panelState === 2">
  245. <ImgPanel :selectedImg="addPicElement" :themeId="itemId" :isButton="false" />
  246. </div>
  247. <!-- 添加多图上元素 3 -->
  248. <div class="panel panel-element clearfix" v-if="panelState === 3">
  249. <ImgPanel :selectedImg="addMorePicElement" :ismultiple="true" />
  250. </div>
  251. <!-- 添加按钮 4 -->
  252. <div class="panel panel-element clearfix" v-if="panelState === 4">
  253. <ImgPanel :selectedImg="addButtonElement" :themeId="itemId" :isButton="true" />
  254. </div>
  255. <!-- 图层编辑面板 -->
  256. <EditPanel :element="element" :panelState="panelState" v-if="panelState > 10" />
  257. </div>
  258. </div>
  259. </section>
  260. <PreView :itemId="itemId" @hideView="showPreView=false" v-if="showPreView" />
  261. </div>
  262. </template>
  263. <script>
  264. import tools from "../../util/tools";
  265. import Overview from "./overview";
  266. import Page from "../../components/Page";
  267. import PicPicker from "../../components/PicturePicker";
  268. import PreView from "../../components/PreView";
  269. import HeaderEdit from "../../components/HeaderEdit";
  270. import EditPanel from "../../components/EditPanel";
  271. import SvgPanel from "../../components/SvgPanel";
  272. import ImgPanel from "../../components/ImgPanel";
  273. import appConst from "../../util/appConst";
  274. import html2canvas from "html2canvas";
  275. import { uploadBase64 } from "../../util/http";
  276. import elabCanvas from "../../util/canvas/elabCanvas.vue";
  277. import elabBackgroundCanvas from "../../util/canvas/elabBackgroundCanvas";
  278. import AudioPanel from "../../components/AudioPanel";
  279. import HeaderMain from "../../components/HeaderMain";
  280. const $ = require("jquery");
  281. export default {
  282. data() {
  283. return {
  284. itemId: null,
  285. testcaseId: null,
  286. panelState: 0,
  287. canvasWidth: 750,
  288. canvasHeight: 504,
  289. bodyBackgroundColor: "rgba(255,255,255,0)",
  290. bgc: "#B1C096",
  291. btnColor: "#5f8a61",
  292. title: "标题",
  293. description: "描述",
  294. dialogSaveBeforeBack: false,
  295. picBase64: "",
  296. http: appConst.BACKEND_DOMAIN,
  297. releaseUrl: "",
  298. showPreView: false,
  299. isLoadingPreview: false,
  300. panelTabState: 0,
  301. animatedNameGlobal: "",
  302. animateGlobalList: [
  303. { id: "Snow", name: "下雪", type: 0 },
  304. { id: "Bubble", name: "冒泡", type: 0 },
  305. { id: "Flower", name: "樱花", type: 0 },
  306. { id: "Rain", name: "下雨", type: 0 },
  307. { id: "Bubble2", name: "飞沙", type: 0 },
  308. { id: "Particles", name: "粒子", type: "0" },
  309. { id: "Circle", name: "圆圈", type: "0" },
  310. { id: "FlowField", name: "流场", type: "0" },
  311. { id: "cloud", name: "云飘", type: "0" },
  312. { id: "nephelo", name: "雾霾", type: "0" }
  313. ],
  314. animateBackgroundGlobalList: [
  315. { id: "Smoke", name: "烟雾", type: 1 },
  316. { id: "Wave", name: "波浪", type: 2 },
  317. // {id: 'WaterRipple', name: '水波', type: 3},
  318. { id: "Bubble2", name: "飞沙", type: 0 },
  319. { id: "Particles", name: "粒子", type: "0" },
  320. { id: "Circle", name: "圆圈", type: "0" },
  321. { id: "FlowField", name: "流场", type: "0" },
  322. { id: "ColorRandom", name: "渐变色", type: "0" }
  323. ],
  324. animatedNameBackgroundGlobal: "",
  325. animatedBackgroundCustom: false,
  326. globalAnimatedBackgroundTag: false
  327. };
  328. },
  329. watch: {
  330. element() {
  331. let ele = this.$store.state.editor.editorElement;
  332. let type = ele ? ele.type : "null";
  333. this.panelTabState = 0;
  334. var length = this.$store.state.editor.complexEditorElement.length;
  335. if (length > 1) {
  336. type = "group";
  337. this.panelTabState = 3;
  338. }
  339. switch (type) {
  340. case "text":
  341. this.panelState = 11;
  342. break;
  343. case "icon":
  344. case "pic":
  345. this.panelState = 12;
  346. break;
  347. case "audio":
  348. this.panelState = 12;
  349. break;
  350. case "morePic":
  351. this.panelState = 13;
  352. break;
  353. case "frame":
  354. this.panelState = 14;
  355. break;
  356. case "button":
  357. this.panelState = 15;
  358. break;
  359. case "group":
  360. this.panelState = 0;
  361. default:
  362. this.panelState = 0;
  363. }
  364. },
  365. "$store.state.editor.complexEditorElement": function() {
  366. var complexEditorElement = this.$store.state.editor.complexEditorElement;
  367. if (complexEditorElement.length == 0 && this.panelTabState == 3) {
  368. this.panelTabState = 0;
  369. }
  370. }
  371. },
  372. computed: {
  373. themeId() {
  374. return this.$store.state.editor.editorTheme._id;
  375. },
  376. editorPage() {
  377. this.bgc = this.$store.state.editor.editorTheme.bgc || "#B1C096";
  378. this.btnColor =
  379. this.$store.state.editor.editorTheme.btnColor || "#5f8a61";
  380. this.bodyBackgroundColor =
  381. this.$store.state.editor.editorTheme.bodyBackgroundColor ||
  382. "rgba(255,255,255,0)";
  383. this.canvasWidth =
  384. this.$store.state.editor.editorTheme.canvasWidth || 750;
  385. this.canvasHeight = this.$store.state.editor.editorTheme.canvasHeight;
  386. this.description = this.$store.state.editor.editorTheme.description;
  387. this.animatedNameGlobal =
  388. this.$store.state.editor.editorTheme.animatedNameGlobal || "";
  389. this.animatedNameBackgroundGlobal =
  390. this.$store.state.editor.editorTheme.animatedNameBackgroundGlobal || "";
  391. this.title = this.$store.state.editor.editorTheme.title;
  392. this.gridTempField = this.$store.state.editor.gridTempField;
  393. return this.$store.state.editor.editorPage;
  394. },
  395. element() {
  396. let ele = this.$store.state.editor.editorElement;
  397. return ele || {};
  398. },
  399. hideFoot() {
  400. let pages = this.$store.state.editor.editorTheme.pages || [];
  401. let index = pages.indexOf(this.editorPage);
  402. return index == pages.length - 1 ? false : true;
  403. },
  404. complexEditorElement() {
  405. return this.$store.state.editor.complexEditorElement;
  406. }
  407. },
  408. methods: {
  409. dialogSave() {
  410. // return Promise.resolve().then(() => this.save()).then(() => this.$router.replace('themeList'))
  411. if (!window.hasSaveFlag) {
  412. this.$confirm(
  413. "请确保已经将修改的内容保存,否则页面将丢失。是否确认退出编辑?",
  414. "提示",
  415. {
  416. confirmButtonText: "确定",
  417. cancelButtonText: "取消",
  418. type: "warning"
  419. }
  420. )
  421. .then(() => {
  422. window.hasSaveFlag = true;
  423. return Promise.resolve().then(() =>
  424. this.$router.replace("myHistoryTest")
  425. );
  426. })
  427. .catch(() => {});
  428. } else {
  429. return Promise.resolve().then(() =>
  430. this.$router.replace("myHistoryTest")
  431. );
  432. }
  433. },
  434. getPicList(_id) {
  435. this.$store.dispatch("getPicListByThemeId", _id);
  436. },
  437. addPicElement(ele) {
  438. // if (ele) {
  439. let obj = {};
  440. obj.type = "pic";
  441. obj.top = document.getElementById("h5editor").scrollTop;
  442. obj.left = 0;
  443. obj.width = ele.width;
  444. obj.height = ele.height;
  445. obj.imgSrc = ele.filePath;
  446. obj.loop = ele.loop;
  447. this.$store.dispatch("addElement", obj);
  448. // } else {
  449. // this.$store.dispatch('addElement', this.element)
  450. // }
  451. this.element.type = "pic";
  452. },
  453. addMorePicElement(ele) {
  454. // if (ele) {
  455. let obj = {};
  456. obj.type = "morePic";
  457. obj.top = document.getElementById("h5editor").scrollTop;
  458. obj.left = 0;
  459. obj.width = ele.morePic[0].width;
  460. obj.height = ele.morePic[0].height;
  461. obj.imgSrc = ele.filePath;
  462. obj.morePic = ele.morePic;
  463. obj.loop = ele.loop;
  464. this.$store.dispatch("addElement", obj);
  465. this.element.type = "morePic";
  466. },
  467. //添加按钮
  468. addButtonElement(ele) {
  469. // if (ele) {
  470. let obj = {};
  471. obj.type = "button";
  472. obj.top = document.getElementById("h5editor").scrollTop;
  473. obj["text"] = "请输入文本";
  474. obj["lineHeight"] = 1.5;
  475. obj.left = 0;
  476. obj.width = ele.width;
  477. obj.height = ele.height;
  478. obj.imgSrc = ele.filePath;
  479. obj.loop = ele.loop;
  480. this.$store.dispatch("addElement", obj);
  481. // } else {
  482. // this.$store.dispatch('addElement', this.element)
  483. // }
  484. this.element.type = "button";
  485. },
  486. addBG(file) {
  487. this.$store.dispatch("addBGElement", {
  488. type: "bg",
  489. imgSrc: file.filePath
  490. });
  491. },
  492. cleanBG() {
  493. this.$store.dispatch("cleanBG");
  494. },
  495. cleanEle() {
  496. this.$store.dispatch("cleanEle", this.element);
  497. },
  498. addTextElement(type) {
  499. let param = {};
  500. param.top = document.getElementById("h5editor").scrollTop;
  501. param["type"] = "text";
  502. param["text"] = "请输入文本";
  503. param["width"] = 300;
  504. param["lineHeight"] = 1.5;
  505. param["backgroundColor"] = "";
  506. param["verticalAlign"] = "top";
  507. param["display"] = "block";
  508. param["textIndent"] = "0.0";
  509. param["letterSpacing"] = "0.0";
  510. param["allTransparent"] = "";
  511. param["nodeId"] = "Id" + Math.random();
  512. switch (type) {
  513. case "plain":
  514. break;
  515. case "title":
  516. param["fontSize"] = 32;
  517. param["fontWeight"] = "bold";
  518. param["textAlign"] = "center";
  519. break;
  520. case "frame":
  521. param["type"] = "frame";
  522. param["text"] = "";
  523. param["width"] = this.canvasWidth;
  524. param["border"] = "1px solid #000";
  525. param["height"] = 500;
  526. break;
  527. default:
  528. }
  529. this.$store.dispatch("addElement", param);
  530. },
  531. playAnimate() {
  532. this.$store.dispatch("playAnimate");
  533. },
  534. async save() {
  535. var loading = this.$loading({
  536. lock: true,
  537. text: "模板保存中...",
  538. spinner: "el-icon-loading",
  539. background: "rgba(0, 0, 0, 0.7)"
  540. });
  541. if (!hasSaveFlag) {
  542. $(".animated").css("animation-name", "null");
  543. $(".animated>div").css("animation-name", "null");
  544. $(".animated span").css({
  545. animationDelay: "0s",
  546. animationDuration: "0s"
  547. });
  548. await html2canvas(document.querySelector("#canvasPage"), {
  549. useCORS: true,
  550. scale: 0.5,
  551. height: 1334,
  552. logging: false //日志开关,便于查看html2canvas的内部执行流程
  553. }).then(async canvas => {
  554. var result = await uploadBase64({ base64Str: canvas.toDataURL() });
  555. if (result.data.success) {
  556. this.$store.state.editor.editorTheme.cover =
  557. result.data.single.filePath;
  558. } else {
  559. this.$message.error("封面图片上传失败!");
  560. }
  561. });
  562. }
  563. this.$store.state.editor.editorTheme.bgc = this.bgc;
  564. this.$store.state.editor.editorTheme.btnColor = this.btnColor;
  565. this.$store.state.editor.editorTheme.bodyBackgroundColor =
  566. this.bodyBackgroundColor || "rgba(255,255,255,0)";
  567. this.$store.state.editor.editorTheme.canvasWidth =
  568. this.canvasWidth || 750;
  569. this.$store.state.editor.editorTheme.canvasHeight = this.canvasHeight;
  570. this.$store.state.editor.editorTheme.title = this.title;
  571. this.$store.state.editor.editorTheme.description = this.description;
  572. this.$store.state.editor.editorTheme.animatedNameGlobal =
  573. this.animatedNameGlobal || "";
  574. this.$store.state.editor.editorTheme.animatedNameBackgroundGlobal =
  575. this.animatedNameBackgroundGlobal || "";
  576. this.editorPage.elements.forEach(function(element) {
  577. if (element.type == "text") {
  578. var height = window
  579. .getComputedStyle(document.getElementById(element.nodeId))
  580. .height.replace("px", "");
  581. element.height = height;
  582. } else if (element.type == "frame") {
  583. element.children.forEach(function(_element) {
  584. if (_element.type == "text") {
  585. var height = window
  586. .getComputedStyle(document.getElementById(_element.nodeId))
  587. .height.replace("px", "");
  588. _element.height = height;
  589. }
  590. });
  591. }
  592. });
  593. let param = {
  594. id: this.itemId,
  595. jsonString: JSON.stringify(this.$store.state.editor.editorTheme),
  596. updator: "admin"
  597. };
  598. console.log("参数", param);
  599. return this.$store
  600. .dispatch("saveTheme", param)
  601. .then(() => {
  602. loading.close();
  603. å;
  604. this.$message({
  605. message: "保存成功",
  606. type: "success"
  607. });
  608. })
  609. .catch(() => {
  610. loading.close();
  611. });
  612. },
  613. deploy() {
  614. this.isLoadingPreview = true;
  615. this.$store
  616. .dispatch(
  617. "saveTheme",
  618. tools.vue2json(this.$store.state.editor.editorTheme)
  619. )
  620. .then(() => {
  621. setTimeout(() => {
  622. this.showPreView = true;
  623. this.isLoadingPreview = false;
  624. }, 1000);
  625. });
  626. },
  627. selectedElement(element) {
  628. this.$store.dispatch("setEditorElement", element);
  629. },
  630. deleteListener(event) {
  631. if (
  632. event.keyCode === 8 &&
  633. event.target.nodeName !== "INPUT" &&
  634. event.target.nodeName !== "TEXTAREA"
  635. ) {
  636. this.deleteElement();
  637. }
  638. },
  639. deleteElement() {
  640. this.$store.dispatch("deleteSelectedElement");
  641. },
  642. togglePanel(code) {
  643. this.panelState = code;
  644. if (code === 0) {
  645. this.panelTabState = 0;
  646. this.$store.dispatch("setEditorElement", null);
  647. }
  648. },
  649. checkGlobalAnimation(item) {
  650. if (this.animatedNameGlobal != item.id) {
  651. this.animatedNameGlobal = item.id;
  652. this.$store.state.editor.editorTheme.animatedNameGlobal = this.animatedNameGlobal;
  653. } else {
  654. this.animatedNameGlobal = "";
  655. this.$store.state.editor.editorTheme.animatedNameGlobal = "";
  656. }
  657. },
  658. checkBackgroundGlobalAnimation(item) {
  659. if (this.animatedNameBackgroundGlobal != item.id) {
  660. this.animatedNameBackgroundGlobal = item.id;
  661. this.animatedBackgroundCustom = item.type == 0 ? false : true;
  662. this.$store.state.editor.editorTheme.animatedNameBackgroundGlobal = this.animatedNameBackgroundGlobal;
  663. } else {
  664. this.animatedNameBackgroundGlobal = "";
  665. this.$store.state.editor.editorTheme.animatedNameBackgroundGlobal = "";
  666. }
  667. },
  668. bodyBackgroundColorChange() {
  669. this.$store.state.editor.editorTheme.bodyBackgroundColor =
  670. this.bodyBackgroundColor || "rgba(255,255,255,0)";
  671. },
  672. IMChange() {
  673. this.$store.state.editor.editorTheme.bgc = this.bgc;
  674. this.$store.state.editor.editorTheme.btnColor = this.btnColor;
  675. },
  676. toLeft() {
  677. let complexEditorElement = this.complexEditorElement;
  678. let arr = complexEditorElement.map(item => {
  679. return item.left;
  680. });
  681. let min = Math.min.apply(null, arr);
  682. complexEditorElement.forEach(ele => {
  683. ele.left = min;
  684. });
  685. },
  686. toCenter() {
  687. let complexEditorElement = this.complexEditorElement;
  688. let arr = complexEditorElement.map(item => {
  689. return item.left;
  690. });
  691. let total = 0;
  692. for (let i = 0; i < arr.length; i++) {
  693. total += arr[i];
  694. }
  695. let p = total / arr.length;
  696. complexEditorElement.forEach(ele => {
  697. ele.left = p;
  698. });
  699. },
  700. toRight() {
  701. let complexEditorElement = this.complexEditorElement;
  702. let arr = complexEditorElement.map(item => {
  703. return item.width + item.left;
  704. });
  705. let max = Math.max.apply(null, arr);
  706. complexEditorElement.forEach(ele => {
  707. ele.left = max - ele.width;
  708. });
  709. },
  710. toTop() {
  711. let complexEditorElement = this.complexEditorElement;
  712. let arr = complexEditorElement.map(item => {
  713. return item.top;
  714. });
  715. let min = Math.min.apply(null, arr);
  716. complexEditorElement.forEach(ele => {
  717. ele.top = min;
  718. });
  719. },
  720. toVertialCenter() {
  721. let complexEditorElement = this.complexEditorElement;
  722. let arr = complexEditorElement.map(item => {
  723. return item.top;
  724. });
  725. let total = 0;
  726. for (let i = 0; i < arr.length; i++) {
  727. total += arr[i];
  728. }
  729. let p = total / arr.length;
  730. complexEditorElement.forEach(ele => {
  731. ele.top = p;
  732. });
  733. },
  734. toBottom() {
  735. let complexEditorElement = this.complexEditorElement;
  736. let arr = complexEditorElement.map(item => {
  737. return item.height + item.top;
  738. });
  739. let max = Math.max.apply(null, arr);
  740. complexEditorElement.forEach(ele => {
  741. ele.top = max - ele.height;
  742. });
  743. }
  744. },
  745. components: {
  746. Overview,
  747. Page,
  748. PicPicker,
  749. appConst,
  750. PreView,
  751. HeaderEdit,
  752. EditPanel,
  753. SvgPanel,
  754. ImgPanel,
  755. AudioPanel,
  756. elabCanvas,
  757. elabBackgroundCanvas,
  758. HeaderMain
  759. },
  760. created() {
  761. // new SnowCanvas(curWinWidth, curWinHeight);
  762. // new Snow().process()
  763. this.testcaseId = this.$route.query.testcaseId;
  764. this.itemId = this.$route.query.itemId;
  765. if (this.itemId) {
  766. if (!this.pages) {
  767. this.$store.dispatch("getPageByThemeId", this.itemId);
  768. }
  769. // this.getPicList(this.itemId);
  770. } else {
  771. this.$store.dispatch("createTheme");
  772. this.$store.dispatch("addPage");
  773. this.$store.dispatch("cleanPicList");
  774. }
  775. document.addEventListener("keyup", this.deleteListener);
  776. window.onbeforeunload = () => false;
  777. },
  778. destroyed() {
  779. document.removeEventListener("keyup", this.deleteListener);
  780. window.onbeforeunload = null;
  781. }
  782. };
  783. </script>
  784. <style lang="less" scoped>
  785. .tagPage {
  786. position: relative;
  787. }
  788. .tagPage:hover div {
  789. display: block;
  790. }
  791. .page-tag-btn-tip {
  792. width: 80px;
  793. height: 26px;
  794. position: absolute;
  795. left: -85px;
  796. top: 50%;
  797. transform: translateY(-50%);
  798. display: none;
  799. text-align: center;
  800. line-height: 26px;
  801. font-size: 14px;
  802. color: #fff;
  803. background: url(../../assets/images/page_tag_btn_tip.png) center no-repeat;
  804. background-size: cover;
  805. }
  806. .editor {
  807. background-color: rgb(237, 239, 247);
  808. position: relative;
  809. height: 100%;
  810. overflow: hidden;
  811. user-select: none;
  812. }
  813. .section {
  814. position: absolute;
  815. left: 0;
  816. right: 0;
  817. top: 120px;
  818. bottom: 0;
  819. overflow: hidden;
  820. }
  821. .overview {
  822. position: absolute;
  823. left: 0;
  824. width: 225px;
  825. height: 100%;
  826. z-index: 10;
  827. }
  828. .canvas {
  829. /*position: absolute !important;*/
  830. /*top: 50%;*/
  831. /*left: 50%;*/
  832. /*transform: translate(-75%, -50%);*/
  833. border: 2px solid #373f42;
  834. box-shadow: 0px 2px 30px 5px rgba(0, 0, 0, 0.2);
  835. box-sizing: content-box;
  836. margin-bottom: 200px;
  837. }
  838. .container {
  839. /*width: 800px;
  840. height: 860px;
  841. padding: 20px;
  842. position: absolute !important;
  843. top: 50%;
  844. left: 50%;
  845. transform: translate(-75%, -50%);
  846. overflow-y: scroll;
  847. overflow-x: hidden;*/
  848. position: absolute !important;
  849. height: 100%;
  850. width: 770px;
  851. left: 56%;
  852. transform: translate(-55%, -94%);
  853. overflow: scroll;
  854. overflow-x: hidden;
  855. }
  856. .control-panel {
  857. position: absolute;
  858. width: 324px;
  859. height: 100%;
  860. right: 0;
  861. top: 0;
  862. border-left: 1px solid #d6d6d6;
  863. background-color: white;
  864. z-index: 10;
  865. .funcs {
  866. position: absolute;
  867. left: -44px;
  868. top: 0;
  869. height: 100%;
  870. width: 44px;
  871. background-color: white;
  872. border-right: 2px solid #e2e4ee;
  873. box-shadow: 0px 1px 15px 1px rgba(0, 0, 0, 0.2);
  874. .func {
  875. color: white;
  876. background: transparent;
  877. cursor: pointer;
  878. margin-top: 20px;
  879. display: block;
  880. width: 50px;
  881. height: 50px;
  882. &:hover {
  883. color: #000;
  884. }
  885. &.active {
  886. border-right: 1px solid #ececec;
  887. background-color: #ececec;
  888. color: #000;
  889. }
  890. }
  891. }
  892. .wrapper {
  893. height: 100%;
  894. overflow-y: auto;
  895. overflow-x: hidden;
  896. position: relative;
  897. }
  898. .panel {
  899. position: absolute;
  900. left: 0;
  901. top: 0;
  902. height: 100%;
  903. width: 100%;
  904. z-index: 2;
  905. background-color: white;
  906. overflow-y: auto;
  907. overflow-x: hidden;
  908. }
  909. .panel-bg {
  910. .btn {
  911. float: left;
  912. width: 48%;
  913. margin-left: 1%;
  914. margin-right: 1%;
  915. }
  916. .bgs {
  917. float: left;
  918. width: 80px;
  919. height: 80px;
  920. background-repeat: no-repeat;
  921. background-position: center;
  922. background-size: contain;
  923. margin: 5px 5px;
  924. &:hover {
  925. border: 2px solid #18ccc0;
  926. cursor: pointer;
  927. }
  928. }
  929. }
  930. .panel-text {
  931. .btn {
  932. height: 50px;
  933. line-height: 50px;
  934. text-align: center;
  935. border: 2px solid transparent;
  936. &:hover {
  937. cursor: pointer;
  938. border-color: #4e5dff;
  939. }
  940. }
  941. }
  942. }
  943. /* 2018/07/23 所有前台自定义字体,需要放七牛云服务器上,暂时放这个样式文件里面 */
  944. @font-face {
  945. font-family: "PenCrane";
  946. src: url("http://yun-image.elab-plus.com/PenCrane.ttf") format("truetype");
  947. font-weight: normal;
  948. font-style: normal;
  949. }
  950. @font-face {
  951. font-family: 手书体;
  952. src: url("http://yun-image.elab-plus.com/new/手书体.ttf") format("truetype");
  953. font-weight: normal;
  954. font-style: normal;
  955. }
  956. @font-face {
  957. font-family: 汉仪粗仿宋简;
  958. src: url("http://yun-image.elab-plus.com/汉仪粗仿宋简.ttf") format("truetype");
  959. font-weight: normal;
  960. font-style: normal;
  961. }
  962. @font-face {
  963. font-family: 华康黑体W3;
  964. src: url("http://yun-image.elab-plus.com/华康黑体W3.ttf") format("truetype");
  965. font-weight: normal;
  966. font-style: normal;
  967. }
  968. @font-face {
  969. font-family: 华康黑体W7;
  970. src: url("http://yun-image.elab-plus.com/华康黑体W7.ttf") format("truetype");
  971. font-weight: normal;
  972. font-style: normal;
  973. }
  974. @font-face {
  975. font-family: 华康黑体W9;
  976. src: url("http://yun-image.elab-plus.com/华康黑体W9.ttf") format("truetype");
  977. font-weight: normal;
  978. font-style: normal;
  979. }
  980. @font-face {
  981. font-family: 华康黑体W12;
  982. src: url("http://yun-image.elab-plus.com/华康黑体W12.ttf") format("truetype");
  983. font-weight: normal;
  984. font-style: normal;
  985. }
  986. @font-face {
  987. font-family: 华康楷体W5;
  988. src: url("http://yun-image.elab-plus.com/华康楷体W5.ttf") format("truetype");
  989. font-weight: normal;
  990. font-style: normal;
  991. }
  992. @font-face {
  993. font-family: 华康勘亭流W9;
  994. src: url("http://yun-image.elab-plus.com/华康勘亭流W9.ttf") format("truetype");
  995. font-weight: normal;
  996. font-style: normal;
  997. }
  998. @font-face {
  999. font-family: 华康瘦金体W3;
  1000. src: url("http://yun-image.elab-plus.com/华康瘦金体W3.ttf") format("truetype");
  1001. font-weight: normal;
  1002. font-style: normal;
  1003. }
  1004. @font-face {
  1005. font-family: 华康宋体W3;
  1006. src: url("http://yun-image.elab-plus.com/华康宋体W3.ttf") format("truetype");
  1007. font-weight: normal;
  1008. font-style: normal;
  1009. }
  1010. @font-face {
  1011. font-family: 华康宋体W7;
  1012. src: url("http://yun-image.elab-plus.com/华康宋体W7.ttf") format("truetype");
  1013. font-weight: normal;
  1014. font-style: normal;
  1015. }
  1016. @font-face {
  1017. font-family: 华康宋体W12;
  1018. src: url("http://yun-image.elab-plus.com/华康宋体W12.ttf") format("truetype");
  1019. font-weight: normal;
  1020. font-style: normal;
  1021. }
  1022. @font-face {
  1023. font-family: 华康魏碑W7;
  1024. src: url("http://yun-image.elab-plus.com/华康魏碑W7.ttf") format("truetype");
  1025. font-weight: normal;
  1026. font-style: normal;
  1027. }
  1028. @font-face {
  1029. font-family: 华康新综艺W7;
  1030. src: url("http://yun-image.elab-plus.com/华康新综艺W7.ttf") format("truetype");
  1031. font-weight: normal;
  1032. font-style: normal;
  1033. }
  1034. @font-face {
  1035. font-family: 华康雅宋体W9;
  1036. src: url("http://yun-image.elab-plus.com/华康雅宋体W9.ttf") format("truetype");
  1037. font-weight: normal;
  1038. font-style: normal;
  1039. }
  1040. @font-face {
  1041. font-family: 华康圆体W3;
  1042. src: url("http://yun-image.elab-plus.com/华康圆体W3.ttf") format("truetype");
  1043. font-weight: normal;
  1044. font-style: normal;
  1045. }
  1046. @font-face {
  1047. font-family: 华康圆体W5;
  1048. src: url("http://yun-image.elab-plus.com/华康圆体W5.ttf") format("truetype");
  1049. font-weight: normal;
  1050. font-style: normal;
  1051. }
  1052. @font-face {
  1053. font-family: 华康圆体W9;
  1054. src: url("http://yun-image.elab-plus.com/华康圆体W9.ttf") format("truetype");
  1055. font-weight: normal;
  1056. font-style: normal;
  1057. }
  1058. @font-face {
  1059. font-family: 庞门正道标题体增强版;
  1060. src: url("http://yun-image.elab-plus.com/庞门正道标题体增强版.ttf")
  1061. format("truetype");
  1062. font-weight: normal;
  1063. font-style: normal;
  1064. }
  1065. @font-face {
  1066. font-family: 站酷高端黑修订版;
  1067. src: url("http://yun-image.elab-plus.com/站酷高端黑修订版.ttf")
  1068. format("truetype");
  1069. font-weight: normal;
  1070. font-style: normal;
  1071. }
  1072. @font-face {
  1073. font-family: 站酷酷黑;
  1074. src: url("http://yun-image.elab-plus.com/站酷酷黑.ttf") format("truetype");
  1075. font-weight: normal;
  1076. font-style: normal;
  1077. }
  1078. </style>