Преглед на файлове

资讯搜索 新增组件

付宇航 преди 1 година
родител
ревизия
8f2d10c7b2
променени са 3 файла, в които са добавени 247 реда и са изтрити 36 реда
  1. 19 6
      components/upload/index.vue
  2. 11 1
      pages/fuwu/fuwu.vue
  3. 217 29
      pages/informationAdd/informationAdd.vue

+ 19 - 6
components/upload/index.vue

@@ -1,13 +1,12 @@
 <template>
   <view class="align-items" style="margin-top: 20px;margin-bottom: 20px;">
-    <view class="container" style="color: #b2b2b2;">*请上传照片</view>
+    <!-- <view class="container" style="color: #b2b2b2;">*请上传照片</view> -->
     <view class="" style="display: flex; flex-wrap: wrap;margin-top: 10px; margin-left: 10px;">
-      <image src="../../static/images/upload/updateimg.png" mode=""
-             style="width: 200rpx; height: 150rpx; margin: 0 12rpx; " @click="choose()"></image>
+      
       <view v-for="(item,index) in imgArr" :key="index" style="position: relative;">
         <view
             v-if="item.substring(item.length - 3) == 'png' || item.substring(item.length - 3) == 'jpg'|| item.substring(item.length-4)=='jpeg' ">
-          <image :src="loadImgSrcLocalhost(item)" mode="" style="width: 100rpx; height: 100rpx; margin: 0 12rpx;"
+          <image :src="loadImgSrcLocalhost(item)" mode="" style="width: 200rpx; height: 150rpx; margin: 0 12rpx;"
                  @click="showPhoto(index)">
           </image>
         </view>
@@ -20,6 +19,8 @@
           </image>
         </view>
       </view>
+	  <image src="../../static/images/upload/updateimg.png" mode=""
+	         class="uploadPic" @click="choose()"></image>
     </view>
   </view>
 </template>
@@ -111,7 +112,8 @@ export default {
                   _this.$modal.msg(data.msg)
                 } else {
                   if (_this.progress === 100) {
-                    _this.imgArr.push(data.fileName)
+                    _this.imgArr.unshift(data.fileName)
+					console.log(_this.imgArr)
                     _this.$modal.msg('上传成功!')
                     _this.photo = false;
                     _this.$emit('updateImg', _this.imgArr);
@@ -236,5 +238,16 @@ export default {
 
 </script>
 
-<style>
+<style lang="scss">
+	.uploadPic{
+		position: relative;
+		height: 150rpx; 
+		margin: 0 12rpx; 
+		width: 200rpx; 
+	}
+	.uploadPic::after{
+		position: absolute;
+		content:'请上传图片';
+		bottom: 0;
+	}
 </style>

+ 11 - 1
pages/fuwu/fuwu.vue

@@ -1,6 +1,10 @@
 <template>
     <!-- pages/me.wxml -->
 	<view class="container">
+		<uni-search-bar @confirm="search" :focus="true" v-model="searchValue" @blur="search"  @input="search"
+		style="width: 100%;"
+			@cancel="cancel">
+		</uni-search-bar>
 	    <view class="rnwdList">
 	        <view class="list" @tap="goDetails(item)" v-for="(item, index1) in qbwd" :key="index1">
 	            <span class="listTitle">{{ item.titleName }}</span>
@@ -43,7 +47,7 @@
 			</view>
 	    </view>
 		<!-- 新增资讯按钮 -->
-		<button class="addInfomarionBtn" @click="addInfomation()"></button>
+		<!-- <button class="addInfomarionBtn" @click="addInfomation()"></button> -->
 	</view>
 </template>
 
@@ -62,6 +66,7 @@ export default {
 			  flag:''
 			},
 			total:0,
+			searchValue:''
 		};
     },
 	created(){
@@ -85,6 +90,11 @@ export default {
 		}
 	},
 	methods:{
+		search(){
+			this.listParams.titleName = this.searchValue
+			this.qbwd = []
+			this.getList()
+		},
 		getList(){
 			listWxs(this.listParams).then(res => {
 				this.qbwd = [...this.qbwd,...res.rows]

+ 217 - 29
pages/informationAdd/informationAdd.vue

@@ -5,55 +5,243 @@
  *@version: V1.0.5
 */
 <template>
-	<view class="container">
-		<u-form :model="form" ref="uForm">
-			<u-form-item label="标题"><u-input v-model="form.titleName" /></u-form-item>
-		</u-form>
+	<view>
+		<uni-forms :rules="rules" :value="formData" ref="form" validate-trigger="bind" err-show-type="undertext" class="uniForm">
+			<uni-group title="基本信息" top="0">
+				<uni-forms-item name="name" required label="标题">
+					<uni-easyinput type="text" :inputBorder="true" v-model="formData.titleName" placeholder="请输入标题"></uni-easyinput>
+				</uni-forms-item>
+				<!-- 使用原生input,需要绑定binddata -->
+				<uni-forms-item name="textDetails" required label="正文">
+					<uni-easyinput type="textarea" v-model="formData.textDetails" :maxlength="50" @blur="binddata('textDetails', $event.detail.value)" placeholder="请输入正文"></uni-easyinput>
+				</uni-forms-item>
+				<uni-forms-item name="checked" label="是否政策推荐" label-width="30%">
+					<switch :checked="formData.isGovernment" @change="change('isGovernment', $event.detail.value)" style="margin-top: 3%;"/>
+				</uni-forms-item>
+				<uni-forms-item name="checked" label="是否置顶" label-width="30%">
+					<switch :checked="formData. isTop" @change="change(' isTop', $event.detail.value)" style="margin-top: 2%;"/>
+				</uni-forms-item>
+				<uni-forms-item name="urlList" required label="图片">
+					<upload :imgArr="imageList" :fileSize="1" :limit="3" @updateImg="updateImg"></upload>
+				</uni-forms-item>
+			</uni-group>
+			<view>
+				<!-- <button  @click="submitForm('form')">校验表单</button>
+				<button size="mini" @click="validateField('form')">只校验用户名和邮箱项</button>
+				<button size="mini" @click="clearValidate('form', 'name')">移除用户名的校验结果</button>
+				<button size="mini" @click="clearValidate('form')">移除全部表单校验结果</button>
+				<button  @click="resetForm">重置表单</button> -->
+				<button  @click="submitForm('form')">新增</button>
+			</view>
+		</uni-forms>
 	</view>
 </template>
-
+ 
 <script>
+	import upload from '@/components/upload/index.vue'
 	export default {
-		data(){
+		components: {
+			upload
+		},
+		data() {
 			return {
-				form: {
+				formData: {
 					titleName: '',
-					intro: '',
-					sex: ''
+					textDetails: '',
+					email: '',
+					sex: '0',
+					hobby: [0, 2],
+					remarks: '热爱学习,热爱生活',
+					isGovernment: false,
+					isTop: false,
+					country: 2,
+					weight: 120,
+					birth: ''
 				},
-				checkboxList: [
-					{
-						name: '苹果',
-						checked: false,
-						disabled: false
+				imageList:[],
+				sex: [{
+						text: '男',
+						value: '0'
 					},
 					{
-						name: '雪梨',
-						checked: false,
-						disabled: false
+						text: '女',
+						value: '1'
 					},
 					{
-						name: '柠檬',
-						checked: false,
-						disabled: false
+						text: '未知',
+						value: '2'
 					}
 				],
-				radioList: [
+				hobby: [{
+						text: '足球',
+						value: 0
+					},
 					{
-						name: '鲜甜',
-						disabled: false
+						text: '篮球',
+						value: 1
 					},
 					{
-						name: '麻辣',
-						disabled: false
+						text: '游泳',
+						value: 2
 					}
 				],
-				radio: '',
-				switchVal: false
+				range: ['中国', '美国', '澳大利亚'],
+				show: false,
+				rules: {
+					titleName: {
+						rules: [{
+								required: true,
+								errorMessage: '请输入标题'
+							},
+							{
+								minLength: 1,
+								errorMessage: '标题不得为空'
+							}
+						]
+					},
+					textDetails: {
+						rules: [{
+								required: true,
+								errorMessage: '请输入正文'
+							},
+							{
+								minLength: 10,
+								errorMessage: '正文不得少于 {minLength} 字'
+							}
+						]
+					},
+					weight: {
+						rules: [{
+								format: 'number',
+								errorMessage: '体重必须是数字'
+							},
+							{
+								minimum: 100,
+								maximum: 200,
+								errorMessage: '体重应该大于 {minimum} 斤,小于 {maximum} 斤'
+							}
+						]
+					},
+					birth: {
+						rules: [
+							{
+								required: true,
+								errorMessage: '请选择时间'
+							},
+							{
+								format: 'timestamp',
+								errorMessage: '必须是时间戳'
+							}
+						]
+					},
+					email: {
+						rules: [{
+							format: 'email',
+							errorMessage: '请输入正确的邮箱地址'
+						}]
+					},
+					isGovernment: {
+						rules: [{
+							format: 'bool'
+						}]
+					},
+					isTop: {
+						rules: [{
+							format: 'bool'
+						}]
+					},
+					sex: {
+						rules: [{
+							format: 'string'
+						}]
+					},
+					hobby: {
+						rules: [{
+								format: 'array'
+							},
+							{
+								validateFunction: function(rule, value, data, callback) {
+									if (value.length < 2) {
+										callback('请至少勾选两个兴趣爱好')
+									}
+									return true
+								}
+							}
+						]
+					}
+				}
+			}
+		},
+		methods: {
+			change(name, value) {
+				this.formData.checked = value
+				this.$refs.form.setValue(name, value)
+			},
+ 
+			submitForm(form) {
+				this.$refs[form]
+					.submit()
+					.then(res => {
+						console.log('表单的值:', res)
+						uni.showToast({
+							title: '验证成功'
+						})
+					})
+					.catch(errors => {
+						console.error('验证失败:', errors)
+					})
+			},
+ 
+			//重置表单 。原生的组件input组件不能重置表单
+			resetForm() {
+				this.$refs.form.resetFields()
+			},
+			validateField(form) {
+				this.$refs[form]
+					.validateField(['name', 'email'])
+					.then(res => {
+						uni.showToast({
+							title: '验证成功'
+						})
+						console.log('表单的值:', res)
+					})
+					.catch(errors => {
+						console.error('验证失败:', errors)
+					})
+			},
+			updateImg(imgList){
+				this.imageList = imgList;
+			},
+			clearValidate(form, name) {
+				if (!name) name = []
+				this.$refs[form].clearValidate(name)
 			}
 		}
 	}
 </script>
-
-<style>
+<style lang="scss">
+	.uniForm{
+		.uni-forms-item{
+			margin: auto;
+			.uni-forms-item__content{
+				margin: auto;
+			}
+		}
+	}
+	.radioView{
+		margin: auto;
+		.uni-forms-item__content{
+			margin: auto;
+		}
+	}
+	.uni-input-border {
+		padding: 0 10px;
+		height: 35px;
+		width: 100%;
+		font-size: 14px;
+		color: #666;
+		border: 1px #e5e5e5 solid;
+		border-radius: 5px;
+		box-sizing: border-box;
+	}
 </style>