index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <QStemplate :title="title" :titleHide="titleHide" :fontSize="fontSize" :width="width" :titleFlex="titleFlex"
  3. :contentFlex="contentFlex" :titleStyle="titleStyle" :contentStyle="contentStyle" :required="required" :requiredSign="requiredSign"
  4. :layout="layout" :titleLayout="titleLayout" :itemDisabled="itemDisabled" :titleColor="titleColor">
  5. <view class="flex_row_none_c width100 padding_10rpx_15rpx">
  6. <view class="Flex5 position_relative" :class="itemLayout_computed">
  7. <textarea
  8. :value="value"
  9. :placeholder="placeholder||('请输入' + title)"
  10. :placeholder-style="textareaSet.placeholder_style"
  11. :placeholder-class="textareaSet.placeholder_class"
  12. :disabled="disabled"
  13. :maxlength="textareaSet.maxlength||140"
  14. :focus="focusBl"
  15. :auto-height="autoHeight"
  16. :cursor-spacing="textareaSet.cursor_spacing"
  17. :cursor="textareaSet.cursor"
  18. :show-confirm-bar="textareaSet.show_confirm_bar"
  19. :selection-start="textareaSet.selection_start"
  20. :selection-end="textareaSet.selection_end"
  21. :adjust-position="textareaSet.adjust_position"
  22. @focus="focusChange()"
  23. @blur="blurChange()"
  24. @linechange="linechange()"
  25. @input="inputs_change($event)"
  26. v-show="!itemDisabled"
  27. :style="{
  28. 'font-size': fontSize + 'rpx',
  29. 'opacity': itemDisabled?0:1,
  30. 'height': getHeight + 'px',
  31. 'width': textareaWidth + '%',
  32. 'background-color': textareaBackgroundColor,
  33. 'border': '1px solid ' + (focusBl?focusBorderColor:blurBorderColor)
  34. }"
  35. class="fontColor666666 border_radius_12rpx textarea" >
  36. </textarea>
  37. <view
  38. class="fontColor666666 textareaItemDis flex_row border_radius_12rpx textarea"
  39. :style="{
  40. 'font-size': fontSize + 'rpx',
  41. 'height': getHeight + 'px',
  42. 'width': textareaWidth + '%',
  43. 'background-color': textareaBackgroundColor,
  44. 'border': '1px solid ' + (focusBl?focusBorderColor:blurBorderColor)
  45. }"
  46. v-if="itemDisabled">
  47. {{value || placeholder || ('请输入' + title)}}
  48. </view>
  49. </view>
  50. </view>
  51. </QStemplate>
  52. </template>
  53. <script>
  54. import _app from '../../js/app.js';
  55. import QStemplate from '../../template/template.vue';
  56. import QSInputsMixin from '../../js/QSInputsMixin.js';
  57. export default {
  58. components: {
  59. QStemplate
  60. },
  61. props: {
  62. textareaSet: {
  63. type: Object,
  64. default () {
  65. return {};
  66. }
  67. },
  68. focus: {
  69. type: Boolean,
  70. default: false
  71. },
  72. focusBorderColor: {
  73. type: String,
  74. default: '#999'
  75. },
  76. blurBorderColor: {
  77. type: String,
  78. default: '#f2f2f2'
  79. },
  80. disabled: {
  81. type: Boolean,
  82. default: false
  83. },
  84. autoHeight: {
  85. type: Boolean,
  86. default: false
  87. },
  88. placeholder: {
  89. type: String,
  90. default: ''
  91. },
  92. filterFc: {
  93. type: Function,
  94. default: null
  95. },
  96. filterType: {
  97. type: String,
  98. default: ''
  99. },
  100. verifyFc: {
  101. type: Function,
  102. default: null
  103. },
  104. verifyType: {
  105. type: String,
  106. default: ''
  107. },
  108. inputDebounceSet: {
  109. type: Object,
  110. default () {
  111. return {
  112. openInputDebounce: true,
  113. delay: 500
  114. };
  115. }
  116. },
  117. textareaHeight: {
  118. type: [String, Number],
  119. default: 12
  120. },
  121. textareaWidth: {
  122. type: [String, Number],
  123. default: 80
  124. },
  125. textareaBackgroundColor: {
  126. type: String,
  127. default: '#f8f8f8'
  128. }
  129. },
  130. computed: {
  131. getHeight() {
  132. return Number(this.textareaHeight)/100*_app.Sys.screenHeight;
  133. }
  134. },
  135. data() {
  136. return {
  137. focusBl: this.focus,
  138. inputDebounce: {}
  139. }
  140. },
  141. watch: {
  142. itemDisabled(n, o) {
  143. if (n && this.focusBl) {
  144. uni.hideKeyboard();
  145. this.blurChange();
  146. }
  147. },
  148. value(n, o) {
  149. console.log('value改变了, 改变之前:' + o + ',改变之后:' + n)
  150. }
  151. },
  152. methods: {
  153. inputs_change({
  154. detail: {
  155. value
  156. }
  157. } = {}) { // 用户输入时,根据index赋值
  158. //_app.log(e.detail.value);
  159. // _app.log(index);
  160. const inputDebounce = this.inputDebounce;
  161. if (this.inputDebounceSet.openInputDebounce) {
  162. if (inputDebounce.debounce) clearTimeout(inputDebounce.debounce);
  163. if (inputDebounce.debounceTime && new Date().getTime() - inputDebounce.debounceTime < (
  164. this.inputDebounceSet.delay || 500)) {
  165. _app.log('防抖冲突,立即执行')
  166. this.inputs_changeFc(value, true);
  167. } else {
  168. inputDebounce.debounce = setTimeout(() => {
  169. _app.log('防抖')
  170. this.inputs_changeFc(value);
  171. }, this.inputDebounceSet.delay || 500);
  172. }
  173. } else {
  174. _app.log('无防抖')
  175. this.inputs_changeFc(value);
  176. }
  177. },
  178. inputs_changeFc(value, clash) {
  179. const inputDebounce = this.inputDebounce;
  180. if (this.inputDebounceSet.openInputDebounce) {
  181. if (clash) inputDebounce.debounceTime = 0;
  182. else inputDebounce.debounceTime = new Date().getTime();
  183. }
  184. if (this.filterFc && typeof(this.filterFc) == 'function') { //有filterFc则过滤
  185. this.input_filter_change(value, this.filterFc);
  186. } else if (this.filterType && _app.filterTypeObj[this.filterType] && typeof(_app.filterTypeObj[this.filterType]) ==
  187. 'function') {
  188. this.input_filter_change(value, _app.filterTypeObj[this.filterType]);
  189. } else {
  190. this.setValue(value);
  191. }
  192. },
  193. input_filter_change(value, filterFc) {
  194. const val = filterFc(value);
  195. if(val != value) {
  196. new Promise((reslove,reject)=>{
  197. this.setValue(' ');
  198. reslove();
  199. })
  200. .then(()=>{
  201. // setTimeout(()=>{
  202. this.setValue(val);
  203. // }, 10)
  204. })
  205. }else{
  206. this.setValue(val);
  207. }
  208. },
  209. focusChange(e) {
  210. if (!this.itemDisabled) this.focusBl = true;
  211. this.$emit('focus', e);
  212. },
  213. blurChange(e) {
  214. this.focusBl = false;
  215. this.$emit('blur', e);
  216. },
  217. linechange(e) {
  218. this.$emit('linechange', e);
  219. }
  220. },
  221. mixins: [QSInputsMixin({
  222. QSInputsType: _app.typeObj.textarea
  223. })]
  224. };
  225. </script>
  226. <style scoped>
  227. @import url("../../css/inputs.css");
  228. .textarea{
  229. transition: border-color .6s;
  230. padding: 20rpx;
  231. }
  232. </style>