xy 11 月之前
父節點
當前提交
f5459ffc41

+ 7 - 4
xs-app/App.vue

@@ -1,7 +1,7 @@
 <script>
     import { config } from './config/config';
-import { sdkUtil } from './framework/sdkUtil';
-import { tools } from './framework/tools';
+	import { sdkUtil } from './framework/sdkUtil';
+	import { tools } from './framework/tools';
 
 	import { UserStatus } from './stores/userStatusManager';
 	const novelPlugin = requirePlugin('novel-plugin');
@@ -52,7 +52,7 @@ import { tools } from './framework/tools';
 	function onNovelPluginLoad(data) {
 	  // data.id 句柄 用来获取novelManager实例
 	  const novelManager = novelPlugin.getNovelManager(data.id);
-				 console.log(novelManager.getPluginInfo())
+	 console.log(novelManager.getPluginInfo())
 	  // getId() 返回当前manager对应的Id(即句柄)
 	  console.log('id:', novelManager.getId());
 
@@ -109,7 +109,10 @@ import { tools } from './framework/tools';
 		
 	
 	  });
-
+	  
+	  novelManager.setCustomServerParams({
+		  customServerParams:JSON.stringify({applet_id:config.applet_id})
+	  })
 	  // setContents 设置目录信息(Object params)
 	  // params.contents Array类型 是一个代表各个章节信息的数组
 	  // params.contents[i].index  number类型 代表章节下标(章节下标从0开始)

+ 2 - 2
xs-app/data/data.ts

@@ -26,10 +26,10 @@ export class banner_data {
 }
 
 export class chapter_item_data{
-	coin:number;
+	coin:number; //消耗
 	id:number;
 	name:string;
-	pay_type:number;
+	pay_type:number; //1收费 0 免费
 	word_count:number;
 }
 

+ 25 - 19
xs-app/framework/sdkUtil.ts

@@ -2,6 +2,7 @@ import { config } from "../config/config"
 import { wx_pay_data } from "../data/data";
 import { log } from "./log"
 import { tools } from "./tools"
+import { util } from "./util";
 // export default {
 //   onShareAppMessage() {
 //     return {
@@ -47,25 +48,30 @@ export class sdkUtil {
 	public static showPayment(data:wx_pay_data,cb:Function){
 		switch (tools.platform){
 			case config.Platform.WEIXIN:
-			    wx.requestPayment({
-					timeStamp: data.timeStamp,
-					nonceStr: data.nonceStr,
-					package: data.package,
-					paySign: data.paySign,
-					signType:"RSA",
-					success: (res) => {
-						console.log("showPayment - success",res)
-						  cb && cb(null,res)
-					},
-					fail: (res) => {
-						console.log("showPayment - fail",res)
-						  cb && cb("fail!",res)
-					},
-					complete: (res) => {
-						console.log("showPayment - complete",res,data)
-						  // cb && cb(res)
-					}
-				});
+				let wx_Info = wx.getSystemInfoSync()
+				if(wx_Info.platform == 'ios'){
+					util.showInfoToast("ios 支付!,请调用客服!")
+				}else{
+					wx.requestPayment({
+						timeStamp: data.timeStamp,
+						nonceStr: data.nonceStr,
+						package: data.package,
+						paySign: data.paySign,
+						signType:"RSA",
+						success: (res) => {
+							console.log("showPayment - success",res)
+							  cb && cb(null,res)
+						},
+						fail: (res) => {
+							console.log("showPayment - fail",res)
+							  cb && cb("fail!",res)
+						},
+						complete: (res) => {
+							console.log("showPayment - complete",res,data)
+							  // cb && cb(res)
+						}
+					});
+				} 
 				break;
 			case config.Platform.TOUTIAO:
 

+ 6 - 0
xs-app/framework/util.ts

@@ -268,4 +268,10 @@ export class util {
 		return str
 	}
 	
+	public static reLaunch(url:string){
+		uni.reLaunch({
+			url:url
+		})
+	}
+	
 }

+ 23 - 3
xs-app/stores/userStatusManager.ts

@@ -1,10 +1,13 @@
 import {defineStore} from 'pinia';
 
-import {reactive} from 'vue';
-import { book_item_data, user_status } from '../data/data';
+import {reactive,ref} from 'vue';
+import { book_item_data, chapter_item_data, user_status } from '../data/data';
+import { tools } from '../framework/tools';
 export const UserStatus = defineStore('user-status',()=>{
 	let data:user_status = reactive(new user_status())
+	let directoryList = ref<chapter_item_data[]>(null)
 	async function updateUserSelectBook(d:book_item_data){
+		directoryList.value = null
 		data.cur_select_book_data=d;
 	}
 	function getUserSelectBook():book_item_data{
@@ -16,5 +19,22 @@ export const UserStatus = defineStore('user-status',()=>{
 		}
 		return data.cur_select_book_data
 	}
-	return {data,getUserSelectBook,updateUserSelectBook}
+	
+	function getSelectBookDirectoryList(call_back){
+		if(directoryList.value!=null){
+			call_back(directoryList.value)
+		}else{
+			let selectBook = getUserSelectBook()
+			if(selectBook!=null){
+				tools.getChapterList(selectBook.chapter_path,(chapter_ls)=>{
+					directoryList.value = chapter_ls
+					call_back(directoryList.value)
+				})
+			}else{
+				call_back(null)
+			}
+		}
+		
+	}
+	return {data,getUserSelectBook,updateUserSelectBook,getSelectBookDirectoryList}
 })

+ 84 - 5
xs-app/wxcomponents/charge-dialog/charge-dialog.js

@@ -1,3 +1,12 @@
+import { config } from "../../config/config";
+import { user_data } from "../../data/data";
+import { http } from "../../framework/http";
+import { log } from "../../framework/log";
+import { tools } from "../../framework/tools";
+import { util } from "../../framework/util";
+import { UserData } from "../../stores/userDataManager";
+import { UserStatus } from "../../stores/userStatusManager";
+
 const novelPlugin = requirePlugin('novel-plugin');
 
 Component({
@@ -18,9 +27,75 @@ Component({
 
   data: {
     loading: false,
+	status_name: "解锁",
+	chapter_data:null,
   },
+ lifetimes:{
+	 attached(){
+		let chapterIndex = this.properties.chapterIndex
+		setTimeout(()=>{
+			UserStatus().getSelectBookDirectoryList((list)=>{
+				if(list!=null){
+					for (var i = 0; i < list.length; i++) {
+						if((list[i].id-1) == chapterIndex){
+							this.data.chapter_data = list[i]
+							break
+						}
+					}
+					console.log("chapter_data",this.data.chapter_data)
+					if(this.data.chapter_data!=null){
+						this.data.status_name = `解锁需要${this.data.chapter_data.coin}书币`
+						this.setData({status_name:this.data.status_name})
+					}
+				}
+			
+			})
+		},100)
+	
+	 }
+ },
+ pageLifetimes:{
+	show() {
+		
+	},
 
+ },
   methods: {
+	get_status_name(){
+		return  this.data.status_name
+	},
+	
+	BuyBookChapter(chapter_id,coin){
+		const novelManager = novelPlugin.getNovelManager(this.properties.novelManagerId);
+		if(UserData().getData().coin>=coin){
+			util.showLoading('正在购买...',true)
+			let book_data = UserStatus().getUserSelectBook()
+			http.DynamicRequest(config.url_confg.Dynamic.buy_chapter,{'book_id':book_data.book_id,'chapter_id':chapter_id},(err,d)=>{
+				if(!err){
+					log.Debug(d)
+					if(d.code==config.url_confg.StatesCode.SUCCESS){
+						// d.content.includes(chapter_id)
+						UserData().update_user_info(()=>{
+							util.hideLoading()
+							util.showInfoToast('购买成功!')
+							novelManager.paymentCompleted()
+						})
+					}else{
+					
+					}
+				}else{
+					log.Error(err)
+				}
+			
+			})
+		}else{
+			util.showModal("书币不足","是否充值?",()=>{
+				novelManager.switchTab({url:'/pages/mine/mine'})
+				// util.reLaunch('/pages/mine/mine')
+			})
+		}
+	
+	},
     // 这里实现自己的付费逻辑
     async pay() {
       // novelManagerId 句柄 用来获取novelManager实例
@@ -32,11 +107,15 @@ Component({
       // getBookId() 返回当前manager对应的bookId
       console.log('bookId:', novelManager.getBookId());
 
-      wx.showModal({
-        title: '付费逻辑',
-        content: '请到components/charge-dialog/charge-dialog.js中完善付费逻辑',
-        showCancel: false,
-      });
+			
+		if(this.data.chapter_data!=null){
+			this.BuyBookChapter(this.properties.chapterIndex+1,this.data.chapter_data.coin)
+		}
+      // wx.showModal({
+      //   title: '付费逻辑',
+      //   content: '请到components/charge-dialog/charge-dialog.js中完善付费逻辑',
+      //   showCancel: false,
+      // });
     },
   },
 })

+ 1 - 1
xs-app/wxcomponents/charge-dialog/charge-dialog.wxml

@@ -1,5 +1,5 @@
 <view class="charge_dialog" style="height: 300px;">
   <button disabled="{{ loading }}" type="primary" bindtap="pay">
-    假装给第{{ chapterIndex + 1 }}章充钱
+	{{status_name}}
   </button>
 </view>