customButtonSettings.vue 13 KB

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