Browse Source

知识库新增

bihuisong 1 year ago
parent
commit
750f7cf5f9
6 changed files with 179 additions and 10 deletions
  1. 7 0
      api/knowledge/knowledge.js
  2. 1 0
      main.js
  3. 14 5
      pages.json
  4. 6 4
      pages/index/index.vue
  5. 16 1
      pages/knowledge/knowledge.vue
  6. 135 0
      pages/knowledge/knowledgeForm.vue

+ 7 - 0
api/knowledge/knowledge.js

@@ -48,4 +48,11 @@ export function addScore(data) {
     method: 'post',
     method: 'post',
 	data:data
 	data:data
   })
   })
+}
+export function addKnowledge(data) {
+  return request({
+    url: '/knowledge/base',
+    method: 'post',
+	data:data
+  })
 }
 }

+ 1 - 0
main.js

@@ -4,6 +4,7 @@ import store from './store' // store
 import plugins from './plugins' // plugins
 import plugins from './plugins' // plugins
 import './permission' // permission
 import './permission' // permission
 import config from '@/config'
 import config from '@/config'
+
 Vue.use(plugins)
 Vue.use(plugins)
 
 
 Vue.config.productionTip = false
 Vue.config.productionTip = false

+ 14 - 5
pages.json

@@ -256,7 +256,7 @@
 				"usingComponents": {},
 				"usingComponents": {},
 				"navigationBarBackgroundColor": "#07c160",
 				"navigationBarBackgroundColor": "#07c160",
 				"enablePullDownRefresh": true,
 				"enablePullDownRefresh": true,
-				"onReachBottomDistance" : 5,
+				"onReachBottomDistance": 5,
 				"navigationBarTextStyle": "white",
 				"navigationBarTextStyle": "white",
 				"navigationBarTitleText": "行情"
 				"navigationBarTitleText": "行情"
 
 
@@ -278,7 +278,7 @@
 				"usingComponents": {},
 				"usingComponents": {},
 				"navigationBarBackgroundColor": "#07c160",
 				"navigationBarBackgroundColor": "#07c160",
 				"enablePullDownRefresh": true,
 				"enablePullDownRefresh": true,
-				"onReachBottomDistance" : 5,
+				"onReachBottomDistance": 5,
 				"navigationBarTextStyle": "white",
 				"navigationBarTextStyle": "white",
 				"navigationBarTitleText": "行情列表"
 				"navigationBarTitleText": "行情列表"
 			}
 			}
@@ -377,6 +377,15 @@
 			}
 			}
 		},
 		},
 		{
 		{
+			"path": "pages/knowledge/knowledgeForm",
+			"style": {
+				"usingComponents": {},
+				"navigationBarBackgroundColor": "#07c160",
+				"navigationBarTextStyle": "white",
+				"navigationBarTitleText": "知识库新增"
+			}
+		},
+		{
 			"path": "pages/travelGuide/travelGuide",
 			"path": "pages/travelGuide/travelGuide",
 			"style": {
 			"style": {
 				"usingComponents": {},
 				"usingComponents": {},
@@ -449,7 +458,7 @@
 			}
 			}
 		},
 		},
 		{
 		{
-			"path" : "pages/topic/topic",
+			"path": "pages/topic/topic",
 			"style": {
 			"style": {
 				"usingComponents": {},
 				"usingComponents": {},
 				"navigationBarBackgroundColor": "#07c160",
 				"navigationBarBackgroundColor": "#07c160",
@@ -458,7 +467,7 @@
 			}
 			}
 		},
 		},
 		{
 		{
-			"path" : "pages/matterAll/matterAll",
+			"path": "pages/matterAll/matterAll",
 			"style": {
 			"style": {
 				"usingComponents": {},
 				"usingComponents": {},
 				"navigationBarBackgroundColor": "#07c160",
 				"navigationBarBackgroundColor": "#07c160",
@@ -518,4 +527,4 @@
 		}]
 		}]
 	},
 	},
 	"subPackages": []
 	"subPackages": []
-}
+}

+ 6 - 4
pages/index/index.vue

@@ -552,15 +552,17 @@
 					userId: getApp().globalData.userId,
 					userId: getApp().globalData.userId,
 					scoreNum: item.integral
 					scoreNum: item.integral
 				};
 				};
+				if (item.purchaseStatus == 0) {
+					this.reduceScore(item)
+					this.addScore(item)
+				}
 				verifyScore(params).then((res) => {
 				verifyScore(params).then((res) => {
 					if (res.data == false) {
 					if (res.data == false) {
 						uni.showToast({
 						uni.showToast({
 							title: '您的积分不足'
 							title: '您的积分不足'
 						})
 						})
-					}else{
-						console.log("verifyScore",res)
-						this.reduceScore(item)
-						this.addScore(item)
+					} else {
+						this.getList()
 						uni.navigateTo({
 						uni.navigateTo({
 							url: '/pages/knowledgeDetails/knowledgeDetails?id=' + item.id,
 							url: '/pages/knowledgeDetails/knowledgeDetails?id=' + item.id,
 						});
 						});

+ 16 - 1
pages/knowledge/knowledge.vue

@@ -23,7 +23,10 @@
 					</view>
 					</view>
 				</view>
 				</view>
 			</view>
 			</view>
+			<uni-fab ref="fab" :horizontal="right" :vertical="bottom"
+			         @fabClick="fabClick()"/>
 		</view>
 		</view>
+
 	</view>
 	</view>
 </template>
 </template>
 
 
@@ -44,6 +47,12 @@
 					pageSize: 10,
 					pageSize: 10,
 				},
 				},
 				loading: false,
 				loading: false,
+				//是否显示弹出层
+				open: false,
+				//悬浮按钮右对齐
+				right: 'right',
+				//悬浮按钮下对齐
+				bottom: 'bottom',
 			}
 			}
 		},
 		},
 		/**
 		/**
@@ -80,7 +89,7 @@
 			getList(pageNum) {
 			getList(pageNum) {
 				let params = {
 				let params = {
 					pageSize: this.queryParams.pageSize,
 					pageSize: this.queryParams.pageSize,
-					pageNum: pageNum,
+					pageNum: pageNum
 				}
 				}
 				list(params).then(res => {
 				list(params).then(res => {
 					if (res.code == 200) {
 					if (res.code == 200) {
@@ -89,6 +98,12 @@
 					}
 					}
 				})
 				})
 			},
 			},
+			//悬浮按钮点击事件
+			fabClick() {
+			  uni.navigateTo({
+			    url: '../knowledge/knowledgeForm'
+			  });
+			},
 		}
 		}
 	}
 	}
 </script>
 </script>

+ 135 - 0
pages/knowledge/knowledgeForm.vue

@@ -0,0 +1,135 @@
+<template>
+	<uni-section title="新增知识库" type="line">
+		<view class="example">
+			<!-- 自定义表单校验 -->
+			<uni-forms ref="customForm" :rules="rules" :modelValue="customFormData" label-align="center">
+				<uni-forms-item label="标题" required name="titleName">
+					<uni-easyinput v-model="customFormData.titleName" placeholder="请输入标题" />
+				</uni-forms-item>
+				<uni-forms-item label="正文" required name="textDetails">
+					<!-- <uni-easyinput v-model="customFormData.textDetails" placeholder="请输入正文" /> -->
+					<mp-html :content="html" />
+				</uni-forms-item>
+				<uni-forms-item label="图片" required name="url">
+					<upload :imgArr="imgUrlList" :fileSize="1" :limit="3" @updateImg="updateImg" />
+				</uni-forms-item>
+				<uni-forms-item label="是否热门" required name="integral">
+					<switch v-model="customFormData.popular" />
+				</uni-forms-item>
+				<uni-forms-item label="付费积分" required name="integral">
+					<uni-number-box v-model="customFormData.integral" />
+				</uni-forms-item>
+			</uni-forms>
+			<button type="primary" @click="submit('customForm')">提交</button>
+		</view>
+	</uni-section>
+</template>
+
+<script>
+	import {
+		addKnowledge
+	} from "@/api/knowledge/knowledge";
+	import upload from '../../components/upload/index.vue'
+	import mpHtml from '@/uni_modules/mp-html/components/mp-html/mp-html.vue'
+	export default {
+		components: {
+			upload,
+			mpHtml
+		},
+		data() {
+			return {
+				html: '<div>Hello World!</div>',
+				// 基础表单数据
+				baseFormData: {
+					titleName: '',
+					textDetails: '',
+					integral: '',
+					popular: '',
+					url: []
+				},
+				// 校验规则
+				rules: {
+					titleName: {
+						rules: [{
+							required: true,
+							errorMessage: '标题不能为空'
+						}]
+					},
+					textDetails: {
+						rules: [{
+							required: true,
+							errorMessage: '正文不能为空'
+						}]
+					}
+				},
+				imgUrlList: [],
+				customFormData: {},
+			}
+		},
+		onLoad() {},
+		onReady() {
+			// 设置自定义表单校验规则,必须在节点渲染完毕后执行
+			this.$refs.customForm.setRules(this.rules)
+		},
+		created() {},
+		methods: {
+			submit(ref) {
+				this.$refs[ref].validate().then(res => {
+					if (res) {
+						if (this.imgUrlList != null && this.imgUrlList != [] && this.imgUrlList.length > 1) {
+							uni.showToast({
+								title: '图片只能上传一张'
+							})
+						} else {
+							this.customFormData.imgUrlList = this.imgUrlList.join(',')
+							addKnowledge(this.customFormData).then(response => {
+								this.$modal.msgSuccess('提交成功');
+								this.customFormData = {
+									...this.baseFormData
+								};
+								this.imgUrlList = [];
+								uni.navigateTo({
+									url: '../knowledge/knowledge'
+								});
+							}).catch(err => {
+								console.log('err', err);
+							})
+						}
+					}
+				})
+			},
+			updateImg(imgUrlList) {
+				this.imgUrlList = imgUrlList;
+			}
+		}
+	}
+</script>
+
+<style lang="scss">
+	.example {
+		padding: 15px;
+		background-color: #fff;
+	}
+
+	.segmented-control {
+		margin-bottom: 15px;
+	}
+
+	.button-group {
+		margin-top: 15px;
+		display: flex;
+		justify-content: space-around;
+	}
+
+	.form-item {
+		display: flex;
+		align-items: center;
+	}
+
+	.button {
+		display: flex;
+		align-items: center;
+		height: 35px;
+		margin-left: 10px;
+	}
+</style>