1
0

prompt_modal.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {{define "modals/promptModal"}}
  2. <a-modal id="prompt-modal" v-model="promptModal.visible" :title="promptModal.title" :closable="true"
  3. @ok="promptModal.ok" :mask-closable="false" :confirm-loading="promptModal.confirmLoading"
  4. :ok-text="promptModal.okText" cancel-text='{{ i18n "cancel" }}' :class="themeSwitcher.currentTheme">
  5. <a-input id="prompt-modal-input" :type="promptModal.type" v-model="promptModal.value"
  6. :autosize="{minRows: 10, maxRows: 20}" @keydown.enter.native="promptModal.keyEnter"
  7. @keydown.ctrl.83="promptModal.ctrlS"></a-input>
  8. </a-modal>
  9. <script>
  10. const promptModal = {
  11. title: '',
  12. type: '',
  13. value: '',
  14. okText: '{{ i18n "sure"}}',
  15. visible: false,
  16. confirmLoading: false,
  17. keyEnter(e) {
  18. if (this.type !== 'textarea') {
  19. e.preventDefault();
  20. this.ok();
  21. }
  22. },
  23. ctrlS(e) {
  24. if (this.type === 'textarea') {
  25. e.preventDefault();
  26. promptModal.confirm(promptModal.value);
  27. }
  28. },
  29. ok() {
  30. promptModal.confirm(promptModal.value);
  31. },
  32. confirm() {},
  33. open({
  34. title = '',
  35. type = 'text',
  36. value = '',
  37. okText = '{{ i18n "sure"}}',
  38. confirm = () => {},
  39. }) {
  40. this.title = title;
  41. this.type = type;
  42. this.value = value;
  43. this.okText = okText;
  44. this.confirm = confirm;
  45. this.visible = true;
  46. promptModalApp.$nextTick(() => {
  47. document.querySelector('#prompt-modal-input').focus();
  48. });
  49. },
  50. close() {
  51. this.visible = false;
  52. },
  53. loading(loading = true) {
  54. this.confirmLoading = loading;
  55. },
  56. };
  57. const promptModalApp = new Vue({
  58. el: '#prompt-modal',
  59. data: {
  60. promptModal: promptModal,
  61. },
  62. });
  63. </script>
  64. {{end}}