customButtonSettings.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <div class="custom-button-settings">
  3. <span class="title">{{ $i18n.t("edit_settings.custom_button") }}</span>
  4. <i
  5. class="iconfont icon-material_prompt tool-tip-for-editor"
  6. v-tooltip="$i18n.t(`edit_settings.custom_button_tips`)"
  7. >
  8. </i>
  9. <br />
  10. <div
  11. v-for="(item, index) of info.customButton"
  12. :key="index"
  13. class="button-setting-item"
  14. :class="{ expand: expandStatus[index] }"
  15. >
  16. <div
  17. class="title-bar"
  18. :class="item.isShow ? 'bright' : 'dark'"
  19. @click="onRequestForChangeExpandStatus(index)"
  20. >
  21. <!-- 新增的体验图片 -->
  22. <div class="experience">
  23. <img src="@/assets/img/experience.png" alt="" />
  24. </div>
  25. <div class="left">
  26. <i class="iconfont icon-edit_input_arrow icon-expand"></i>
  27. <img
  28. v-if="item.type === '电话' && item.isShow"
  29. :src="require('@/assets/images/icons/phone.svg')"
  30. class="button-icon"
  31. alt=""
  32. />
  33. <img
  34. v-if="item.type === '电话' && !item.isShow"
  35. :src="require('@/assets/images/icons/phone-dark.svg')"
  36. class="button-icon"
  37. alt=""
  38. />
  39. <img
  40. v-if="item.type === '链接' && item.isShow"
  41. :src="require('@/assets/images/icons/link.svg')"
  42. class="button-icon"
  43. alt=""
  44. />
  45. <img
  46. v-if="item.type === '链接' && !item.isShow"
  47. :src="require('@/assets/images/icons/link-dark.svg')"
  48. class="button-icon"
  49. alt=""
  50. />
  51. <span class="button-name">
  52. {{ getButtonTypeI18n(item.type) }}
  53. </span>
  54. </div>
  55. <div class="right">
  56. <i
  57. class="iconfont icon-editor_list_edit btn-edit"
  58. @click.stop="onRequestForEdit(index)"
  59. v-tooltip="$i18n.t(`edit_settings.edit`)"
  60. >
  61. </i>
  62. <i
  63. v-show="item.isShow"
  64. class="iconfont icon-editor_on btn-show"
  65. v-tooltip="$i18n.t(`edit_settings.hide`)"
  66. @click.stop="item.isShow = false"
  67. ></i>
  68. <i
  69. v-show="!item.isShow"
  70. class="iconfont icon-editor_off btn-hide"
  71. v-tooltip="$i18n.t(`edit_settings.show`)"
  72. @click.stop="onRequestForShow(index)"
  73. ></i>
  74. </div>
  75. </div>
  76. <div class="edit-content">
  77. <div class="edit-content-item">
  78. <span class="item-name">{{
  79. $i18n.t(`edit_settings.button_type`)
  80. }}</span>
  81. <div style="margin-left: 16px">
  82. {{ getButtonTypeI18n(item.type) }}
  83. </div>
  84. </div>
  85. <div class="edit-content-item">
  86. <span class="item-name">{{
  87. $i18n.t(`edit_settings.button_name`)
  88. }}</span>
  89. <div style="margin-left: 16px">
  90. {{ item.name }}
  91. </div>
  92. </div>
  93. <div class="edit-content-item">
  94. <span class="item-name">{{ buttonValueTips[index] }}</span>
  95. <div style="margin-left: 16px">
  96. {{ item.value }}
  97. </div>
  98. </div>
  99. <div class="edit-content-item" v-if="item.type !== '电话'">
  100. <span class="item-name"
  101. >{{ $i18n.t("edit_settings.button_open_method") }}</span
  102. >
  103. <div style="margin-left: 16px">
  104. {{ $i18n.t(`zh_key.${item.openMethod}`) }}
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. <!-- 编辑框 -->
  110. <popup v-if="isEditing" :canClose="false">
  111. <div class="ui-message ui-message-confirm dark edit-window">
  112. <div class="ui-message-header">
  113. <span>{{ $i18n.t("edit_settings.custom_button") }}</span>
  114. <span @click="isEditing = false">
  115. <i class="iconfont icon_close"></i>
  116. </span>
  117. </div>
  118. <div class="ui-message-main">
  119. <div class="edit-content-item">
  120. <span class="item-name">{{
  121. $i18n.t(`edit_settings.button_name`)
  122. }}</span>
  123. <PulldownMenuInEditor
  124. class="selector"
  125. :valueList="buttonTypeList"
  126. v-model="editingInfo.type"
  127. />
  128. <input
  129. class="name-input"
  130. :placeholder="$i18n.t(`edit_settings.button_placeholder`)"
  131. v-model="editingInfo.name"
  132. maxlength="15"
  133. />
  134. </div>
  135. <div class="edit-content-item">
  136. <span class="item-name">{{ editingButtonValueTip }}</span>
  137. <input
  138. class="value-input"
  139. :placeholder="`${$i18n.t(
  140. `edit_settings.please_input`
  141. )}${editingButtonValueTip}`"
  142. v-model="editingInfo.value"
  143. />
  144. </div>
  145. <div class="edit-content-item full" v-if="!isNotPhoneMode">
  146. <span class="item-name">{{
  147. $i18n.t("edit_settings.button_open_method")
  148. }}</span>
  149. <PulldownMenuInEditor
  150. class="selector"
  151. :valueList="buttonOpenMethodList"
  152. v-model="editingInfo.openMethod"
  153. />
  154. </div>
  155. </div>
  156. <div class="ui-message-footer">
  157. <button class="ui-button deepcancel" @click="isEditing = false">
  158. {{ $i18n.t("gather.cancel") }}
  159. </button>
  160. <button class="ui-button submit" @click="onConfirmEditing">
  161. {{ $i18n.t("gather.comfirm") }}
  162. </button>
  163. </div>
  164. </div>
  165. </popup>
  166. </div>
  167. </template>
  168. <script>
  169. import { mapGetters } from "vuex";
  170. import PulldownMenuInEditor from "@/components/pulldownMenuInEditor.vue";
  171. import { isValidPhoneNumber } from "@/utils/other.js";
  172. import Popup from "@/components/shared/popup/index.vue";
  173. import { i18n } from "@/lang";
  174. export default {
  175. components: {
  176. PulldownMenuInEditor,
  177. Popup,
  178. },
  179. data() {
  180. return {
  181. expandStatus: [],
  182. buttonTypeList: ["电话", "链接"],
  183. buttonOpenMethodList: ["弹出层打开", "新窗口打开"],
  184. isEditing: false,
  185. editingButtonIdx: -1,
  186. editingInfo: {
  187. type: "",
  188. name: "",
  189. value: "",
  190. openMethod: "",
  191. },
  192. };
  193. },
  194. computed: {
  195. ...mapGetters({
  196. info: "info",
  197. }),
  198. isNotPhoneMode() {
  199. //TODO 这个模块都有用中文做为key value (惊了?)
  200. return this.editingInfo.type === "电话";
  201. },
  202. buttonValueTips() {
  203. if (this.info.customButton) {
  204. return this.info.customButton.map((item) => {
  205. if (item.type === "电话") {
  206. return i18n.t("edit_settings.phone");
  207. } else if (item.type === "链接") {
  208. return i18n.t("edit_settings.link");
  209. } else {
  210. return "";
  211. }
  212. });
  213. } else {
  214. return null;
  215. }
  216. },
  217. editingButtonValueTip() {
  218. if (this.editingInfo.type === "电话") {
  219. return i18n.t("edit_settings.phone");
  220. } else if (this.editingInfo.type === "链接") {
  221. return i18n.t("edit_settings.link");
  222. } else {
  223. return "";
  224. }
  225. },
  226. },
  227. watch: {
  228. // editingInfo: {
  229. // handler(val) {
  230. // console.log("editingInfo-1", val);
  231. // },
  232. // immediate: true,
  233. // deep: true,
  234. // },
  235. "editingInfo.type": {
  236. handler(newValue, oldValue) {
  237. this.editingInfo.name = i18n.t(`zh_key.${newValue}`);
  238. if (oldValue && newValue !== oldValue) {
  239. this.editingInfo.value = "";
  240. }
  241. },
  242. },
  243. },
  244. beforeMount() {
  245. if (!this.info.customButton) {
  246. // 这是在v1.2版之前创建的作品,还没设置过自定义按钮,所以还没有customButton字段
  247. this.info.customButton = [
  248. {
  249. type: "电话",
  250. name: "电话",
  251. value: "",
  252. openMethod: "弹出层打开",
  253. isShow: false,
  254. },
  255. {
  256. type: "链接",
  257. name: "链接",
  258. value: "",
  259. openMethod: "弹出层打开",
  260. isShow: false,
  261. },
  262. ];
  263. }
  264. if (!this.info.customButton[0].openMethod) {
  265. // 这是在v1.3版之前创建的作品,还没设置过自定义按钮的打开方式。
  266. this.info.customButton[0].openMethod = "弹出层打开";
  267. this.info.customButton[1].openMethod = "弹出层打开";
  268. }
  269. },
  270. mounted() {
  271. this.info.customButton.forEach((item) => {
  272. item.name =
  273. i18n.t(`zh_key.${item.name}`).indexOf("zh_key") > -1
  274. ? item.name
  275. : i18n.t(`zh_key.${item.name}`);
  276. });
  277. },
  278. methods: {
  279. getButtonTypeI18n(buttonType) {
  280. if (buttonType === "电话") {
  281. return i18n.t("edit_settings.phone_short");
  282. } else if (buttonType === "链接") {
  283. return i18n.t("edit_settings.link_short");
  284. } else {
  285. return "";
  286. }
  287. },
  288. onRequestForChangeExpandStatus(index) {
  289. this.$set(this.expandStatus, index, !this.expandStatus[index]);
  290. },
  291. onRequestForEdit(index) {
  292. this.editingButtonIdx = index;
  293. this.editingInfo.type = this.info.customButton[index].type;
  294. this.editingInfo.name = this.info.customButton[index].name;
  295. this.editingInfo.value = this.info.customButton[index].value;
  296. this.editingInfo.openMethod = this.info.customButton[index].openMethod;
  297. this.isEditing = true;
  298. },
  299. checkButtonName(name) {
  300. if (!name) {
  301. this.$msg.warning(i18n.t("gather.fill_complete"));
  302. return false;
  303. }
  304. return true;
  305. },
  306. checkButtonValue(value, type) {
  307. if (type === "电话") {
  308. if (!isValidPhoneNumber(value)) {
  309. this.$msg.warning(i18n.t("gather.fill_phone"));
  310. return false;
  311. }
  312. } else if (type === "链接") {
  313. if (!value) {
  314. this.$msg.warning(i18n.t("gather.fill_complete"));
  315. return false;
  316. }
  317. }
  318. return true;
  319. },
  320. onConfirmEditing() {
  321. if (!this.checkButtonName(this.editingInfo.name)) {
  322. return;
  323. }
  324. if (
  325. !this.checkButtonValue(this.editingInfo.value, this.editingInfo.type)
  326. ) {
  327. return;
  328. }
  329. this.info.customButton[this.editingButtonIdx].type =
  330. this.editingInfo.type;
  331. this.info.customButton[this.editingButtonIdx].name =
  332. this.editingInfo.name;
  333. this.info.customButton[this.editingButtonIdx].value =
  334. this.editingInfo.value;
  335. this.$msg.success(i18n.t("gather.success"));
  336. this.isEditing = false;
  337. },
  338. onRequestForShow(index) {
  339. if (!this.checkButtonName(this.info.customButton[index].name)) {
  340. return;
  341. }
  342. if (
  343. !this.checkButtonValue(
  344. this.info.customButton[index].value,
  345. this.info.customButton[index].type
  346. )
  347. ) {
  348. return;
  349. }
  350. this.info.customButton[index].isShow = true;
  351. },
  352. },
  353. };
  354. </script>
  355. <style lang="less" scoped>
  356. .custom-button-settings {
  357. padding: 24px 30px;
  358. background: #252526;
  359. height: 546px;
  360. .title {
  361. font-size: 18px;
  362. color: #ffffff;
  363. }
  364. .tool-tip-for-editor {
  365. margin-left: 4px;
  366. font-size: 12px;
  367. cursor: default;
  368. position: relative;
  369. top: -2px;
  370. }
  371. > .button-setting-item {
  372. margin-top: 16px;
  373. position: relative;
  374. min-height: 50px;
  375. > .title-bar {
  376. position: absolute;
  377. width: 100%;
  378. height: 50px;
  379. background: #1a1b1d;
  380. border-radius: 2px;
  381. border: 1px solid #404040;
  382. display: flex;
  383. justify-content: space-between;
  384. align-items: center;
  385. padding: 0 31px 0 16px;
  386. cursor: pointer;
  387. .experience {
  388. position: absolute;
  389. z-index: 10;
  390. top: 0;
  391. right: 0;
  392. & > img {
  393. width: 31px;
  394. height: 31px;
  395. }
  396. }
  397. &.bright {
  398. color: #fff;
  399. }
  400. &.dark {
  401. color: #808080;
  402. }
  403. > .left {
  404. display: flex;
  405. align-items: center;
  406. > .icon-expand {
  407. font-size: 10px;
  408. color: rgba(255, 255, 255, 0.6);
  409. transform: rotate(-90deg);
  410. cursor: pointer;
  411. }
  412. > .button-icon {
  413. width: 18px;
  414. height: 18px;
  415. margin-left: 6px;
  416. }
  417. > .button-name {
  418. font-size: 16px;
  419. margin-left: 6px;
  420. }
  421. }
  422. > .right {
  423. display: flex;
  424. align-items: center;
  425. i.btn-edit {
  426. cursor: pointer;
  427. padding: 7px;
  428. &:hover {
  429. color: #0076f6;
  430. }
  431. }
  432. > .btn-show {
  433. margin-left: 9px;
  434. cursor: pointer;
  435. padding: 7px;
  436. &:hover {
  437. color: #0076f6;
  438. }
  439. }
  440. > .btn-hide {
  441. margin-left: 9px;
  442. cursor: pointer;
  443. padding: 7px;
  444. &:hover {
  445. color: #0076f6;
  446. }
  447. }
  448. }
  449. }
  450. > .edit-content {
  451. border-radius: 2px;
  452. border: 1px solid #404040;
  453. padding-top: 58px;
  454. padding-bottom: 26px;
  455. display: none;
  456. pointer-events: none;
  457. > .edit-content-item {
  458. margin-top: 16px;
  459. display: flex;
  460. align-items: center;
  461. > .item-name {
  462. margin-left: 16px;
  463. font-size: 14px;
  464. color: rgba(255, 255, 255, 0.5);
  465. }
  466. > .selector {
  467. margin-left: 16px;
  468. }
  469. > .name-input {
  470. height: 36px;
  471. background: transparent;
  472. border-radius: 2px;
  473. border: 1px solid #404040;
  474. color: #fff;
  475. font-size: 14px;
  476. padding: 0 16px;
  477. letter-spacing: 1px;
  478. width: 470px;
  479. &:focus {
  480. border-color: #0076f6;
  481. }
  482. }
  483. > .value-input {
  484. margin-left: 16px;
  485. height: 36px;
  486. background: transparent;
  487. border-radius: 2px;
  488. border: 1px solid #404040;
  489. color: #fff;
  490. font-size: 14px;
  491. padding: 0 16px;
  492. letter-spacing: 1px;
  493. width: 610px;
  494. &:focus {
  495. border-color: #0076f6;
  496. }
  497. }
  498. }
  499. }
  500. }
  501. > .button-setting-item.expand {
  502. > .title-bar {
  503. > .left {
  504. > .icon-expand {
  505. transform: rotate(0deg);
  506. }
  507. }
  508. }
  509. > .edit-content {
  510. display: block;
  511. }
  512. }
  513. .edit-window {
  514. width: 574px;
  515. > .ui-message-main {
  516. margin-bottom: 40px;
  517. > .edit-content-item {
  518. margin-top: 16px;
  519. display: flex;
  520. align-items: center;
  521. &.full {
  522. .selector {
  523. width: 610px;
  524. }
  525. }
  526. > .item-name {
  527. flex: 0 0 auto;
  528. font-size: 14px;
  529. color: rgba(255, 255, 255, 0.5);
  530. }
  531. > .selector {
  532. margin-left: 16px;
  533. }
  534. > .name-input {
  535. height: 36px;
  536. background: #252526;
  537. border-radius: 2px;
  538. border: 1px solid #404040;
  539. color: #fff;
  540. font-size: 14px;
  541. padding: 0 16px;
  542. letter-spacing: 1px;
  543. width: 470px;
  544. &:focus {
  545. border-color: #0076f6;
  546. }
  547. }
  548. > .value-input {
  549. margin-left: 16px;
  550. height: 36px;
  551. background: #252526;
  552. border-radius: 2px;
  553. border: 1px solid #404040;
  554. color: #fff;
  555. font-size: 14px;
  556. padding: 0 16px;
  557. letter-spacing: 1px;
  558. width: 610px;
  559. &:focus {
  560. border-color: #0076f6;
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }
  567. </style>