form.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="wrap">
  3. <uni-forms :modelValue="formData" :label-width="50" ref="form">
  4. <uni-forms-item label="标题" name="taskTitle" required>
  5. <uni-easyinput type="text" v-model="formData.taskTitle" placeholder="请输入标题" />
  6. </uni-forms-item>
  7. <uni-forms-item label="内容" name="taskContent" required>
  8. <uni-easyinput
  9. v-model="formData.taskContent"
  10. :maxlength="-1" type="textarea"
  11. autoHeight
  12. placeholder="请输入内容" />
  13. </uni-forms-item>
  14. </uni-forms>
  15. <button @click="submitForm" class="submit-bt">提交</button>
  16. </view>
  17. </template>
  18. <script>
  19. import {createMemory} from '@/api/user.js'
  20. export default {
  21. data() {
  22. return {
  23. rules: {
  24. taskTitle: {
  25. rules:[
  26. {
  27. required: true,
  28. errorMessage: '请填写标题',
  29. }
  30. ],
  31. label:'标题',
  32. validateTrigger:'submit'
  33. },
  34. taskContent: {
  35. rules:[
  36. {
  37. required: true,
  38. errorMessage: '请填写内容',
  39. }
  40. ],
  41. label:'内容',
  42. validateTrigger:'submit'
  43. }
  44. },
  45. formData:{
  46. taskTitle:"",
  47. taskContent:""
  48. }
  49. }
  50. },
  51. onReady() {
  52. this.$refs.form.setRules(this.rules)
  53. },
  54. methods: {
  55. submitForm(){
  56. let accountId=uni.getStorageSync('accountId')
  57. this.$refs.form.validate().then(res => {
  58. createMemory({
  59. ...res,
  60. accountId
  61. }).then((resq)=>{
  62. uni.showToast({
  63. title:"提交成功!",
  64. icon:"none"
  65. })
  66. setTimeout(()=>{
  67. uni.switchTab({
  68. url:'/pages/history/history'
  69. })
  70. },1000)
  71. })
  72. }).catch(err => {
  73. console.log('表单错误信息:', err);
  74. })
  75. }
  76. },
  77. onShareAppMessage() {
  78. return {
  79. title: '记忆',
  80. path: '/pages/index/index'
  81. }
  82. },
  83. onShareTimeline() {
  84. return {
  85. title: '记忆',
  86. path: '/pages/index/index'
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. *{
  93. padding: 0;
  94. margin: 0;
  95. }
  96. .wrap{
  97. padding:20rpx;
  98. .submit-bt{
  99. width: 240rpx;
  100. height: 72rpx;
  101. line-height: 72rpx;
  102. text-align: center;
  103. background:#3D90F4;
  104. border-radius: 36rpx;
  105. font-size: 32rpx;
  106. font-family: PingFang SC;
  107. font-weight: 400;
  108. color: #FFFFFF;
  109. z-index: 999;
  110. float: right;
  111. }
  112. }
  113. </style>