delis.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="gg-container">
  3. <view class="gg-tit">
  4. <view class="gg-title">
  5. 我的吉农宝<text>上个页面传过来的参数{{id}}</text>
  6. </view>
  7. <view>
  8. <uni-section title="基本用法" type="line">
  9. <view class="example">
  10. <!-- 基础用法,不包含校验规则 -->
  11. <uni-forms ref="baseForm" :modelValue="baseFormData">
  12. <uni-forms-item label="姓名" required>
  13. <uni-easyinput v-model="baseFormData.name" placeholder="请输入姓名" />
  14. </uni-forms-item>
  15. <uni-forms-item label="年龄" required>
  16. <uni-easyinput v-model="baseFormData.age" placeholder="请输入年龄" />
  17. </uni-forms-item>
  18. <uni-forms-item label="性别" required>
  19. <uni-data-checkbox v-model="baseFormData.sex" :localdata="sexs" />
  20. </uni-forms-item>
  21. <uni-forms-item label="兴趣爱好" required>
  22. <uni-data-checkbox v-model="baseFormData.hobby" multiple :localdata="hobbys" />
  23. </uni-forms-item>
  24. <uni-forms-item label="自我介绍">
  25. <uni-easyinput type="textarea" v-model="baseFormData.introduction" placeholder="请输入自我介绍" />
  26. </uni-forms-item>
  27. <uni-forms-item label="日期时间">
  28. <uni-datetime-picker type="datetime" return-type="timestamp" v-model="baseFormData.datetimesingle"/>
  29. </uni-forms-item>
  30. </uni-forms>
  31. </view>
  32. </uni-section>
  33. <uni-section title="多行文本" subTitle="指定属性 type=textarea 使用多行文本框" type="line" padding>
  34. <uni-easyinput type="textarea" v-model="value" placeholder="请输入内容"></uni-easyinput>
  35. </uni-section>
  36. <!-- 这张图片就是自定义的图片,地址填写自己本地的就行 -->
  37. <image src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png"
  38. mode="widthFix" style="width: 112rpx;height: 110rpx;" @click="uploadImagePhoto()"></image>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. baseFormData: {
  48. name: '',
  49. age: '',
  50. introduction: '',
  51. sex: 2,
  52. hobby: [5],
  53. datetimesingle: 1627529992399
  54. },
  55. // 单选数据源
  56. sexs: [{
  57. text: '男',
  58. value: 0
  59. }, {
  60. text: '女',
  61. value: 1
  62. }, {
  63. text: '保密',
  64. value: 2
  65. }],
  66. // 多选数据源
  67. hobbys: [{
  68. text: '跑步',
  69. value: 0
  70. }, {
  71. text: '游泳',
  72. value: 1
  73. }, {
  74. text: '绘画',
  75. value: 2
  76. }, {
  77. text: '足球',
  78. value: 3
  79. }, {
  80. text: '篮球',
  81. value: 4
  82. }, {
  83. text: '其他',
  84. value: 5
  85. }],
  86. value: '',
  87. password: '',
  88. placeholderStyle: "color:#2979FF;font-size:14px",
  89. styles: {
  90. color: '#2979FF',
  91. borderColor: '#2979FF'
  92. },
  93. id:'',
  94. fileList1: []
  95. }
  96. },
  97. onLoad(options) {
  98. this.id = options.id;
  99. },
  100. onReady() {},
  101. methods: {
  102. input(e) {
  103. console.log('输入内容:', e);
  104. },
  105. iconClick(type) {
  106. uni.showToast({
  107. title: `点击了${type==='prefix'?'左侧':'右侧'}的图标`,
  108. icon: 'none'
  109. })
  110. },
  111. uploadImagePhoto() {
  112. uni.chooseImage({
  113. count: 6, //默认9
  114. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  115. sourceType: ['album'], //从相册选择
  116. success: function (res) {
  117. }
  118. });
  119. },
  120. // 新增图片
  121. async afterRead(event) {
  122. console.log(event)
  123. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  124. let lists = [].concat(event.file)
  125. let fileListLen = this[`fileList${event.name}`].length
  126. lists.map((item) => {
  127. this[`fileList${event.name}`].push({
  128. ...item,
  129. status: 'uploading',
  130. message: '上传中'
  131. })
  132. })
  133. for (let i = 0; i < lists.length; i++) {
  134. const result = await this.uploadFilePromise(lists[i].url)
  135. let item = this[`fileList${event.name}`][fileListLen]
  136. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  137. status: 'success',
  138. message: '',
  139. url: result
  140. }))
  141. fileListLen++
  142. }
  143. },
  144. //上传图片
  145. uploadFilePromise(url) {
  146. return new Promise((resolve, reject) => {
  147. let a = uni.uploadFile({
  148. //url: this.$common.domain+'/api/common/upload', // 仅为示例,非真实的接口地址
  149. // url:'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  150. filePath: url,
  151. name: 'file',
  152. formData: {
  153. user: 'test'
  154. },
  155. success: (res) => {
  156. let data=JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  157. resolve(data.data.url)
  158. }
  159. });
  160. })
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .uni-mt-5 {
  167. margin-top: 5px;
  168. }
  169. </style>