1
0

customButtonSettings.vue 16 KB

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