index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <view class="pinyin-box">
  3. <view class="pages-box">
  4. <view class="fs32 fc99">请输入您要查询的汉字</view>
  5. <view class="inp-box">
  6. <input @input="valFun" class="inp" placeholder="请输入单个汉字" placeholderStyle="font-size:30rpx" :value="val" />
  7. <view class="inpimg">
  8. <image class="pagesimg" src="/static/images/search.png"></image>
  9. </view>
  10. </view>
  11. <view class="btn-box">
  12. <button @tap="onInput" class="btn fs32">查 询</button>
  13. </view>
  14. </view>
  15. <view :class="'det-box ' + (show ? '' : 'dp-n')">
  16. <view class="pg-t fs36 fc99">详细信息</view>
  17. <view class="pglist fc99 bd-n">
  18. <view class="pg-l fs32">结果:</view>
  19. <view class="pg-r fs32">{{ pinyinText }}</view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. getApp();
  26. export default {
  27. data() {
  28. return {
  29. pinyin: new Object(),
  30. pinyinText: '',
  31. val: '',
  32. show: false
  33. };
  34. },
  35. onLoad: function () {
  36. this.getPinyin();
  37. },
  38. methods: {
  39. getPinyin: function () {
  40. var that = this;
  41. uniCloud.callFunction({
  42. name: 'getPinyin',
  43. data: {}
  44. })
  45. .then(function (n) {
  46. that.pinyin=n.result.data[0].pinyin
  47. });
  48. },
  49. valFun: function (t) {
  50. this.val=t.detail.value;
  51. },
  52. onInput: function (t) {
  53. var n = this.val;
  54. if (1 == (n = n && n.trim()).length) {
  55. if (this.pinyin.hasOwnProperty(n)) {
  56. this.pinyinText=this.pinyin[n].join(', ');
  57. this.show=true;
  58. } else {
  59. this.pinyinText='没有查询到';
  60. this.show=true;
  61. }
  62. } else {
  63. this.pinyinText='请输入单个汉字';
  64. this.show=true;
  65. }
  66. }
  67. }
  68. };
  69. </script>
  70. <style>
  71. @import './index.css';
  72. </style>