index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. // 自定义组件
  3. import '../../../xr-custom/components/AutoRotate';
  4. import '../../../xr-custom/components/Particle/SystemProperty/BasicParticle';
  5. import '../../../xr-custom/components/Particle/index';
  6. import '../../../xr-custom/elements/xr-auto-rotate-touchable-gltf';
  7. import '../../../xr-custom/elements/xr-custom-particle';
  8. // 自定义Geometry
  9. import '../../../xr-custom/assets/geometry-star';
  10. import '../../../xr-custom/assets/geometry-specialCylinder';
  11. // 自定义材质
  12. import '../../../xr-custom/elements/xr-shining-star';
  13. // 自定义effect
  14. import '../../../xr-custom/assets/effect-shining';
  15. import '../../../xr-custom/assets/effect-last-record-final';
  16. //var capate = require("G:/GUnityProject/WXXR/miniprogram/components/xr-classic-show/index.js");
  17. Page({
  18. behaviors:[sceneReadyBehavior],
  19. data:{
  20. captureState: 0,
  21. recordState: 0,
  22. captureQuality: 0.8,
  23. captureType: 'jpg',
  24. recordFPS: 30,
  25. recordScale: 1,
  26. recordWidth: 0,
  27. recordHeight: 0,
  28. recordBPS: 30000,
  29. sceneWidth: 0,
  30. sceneHeight: 0,
  31. zhaohuanstate:true,
  32. paizhaostate:false,
  33. luxiangstate:false,
  34. isStartluxiang:false,
  35. isCloseluxiang:false,
  36. uiShowModelView:false,
  37. UiShowModel_Bottom:false,
  38. uiMainView:true,
  39. uiShowNum:3,
  40. uiShowIndex:0,
  41. current:0,
  42. products:[],
  43. modelImg:[
  44. 'https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/WXImage/%E9%80%89%E6%8B%A9%E7%A5%9E%E5%85%BD-%E5%A4%AB%E8%AF%B8%E9%A2%84%E8%A7%88%E5%9B%BE.png',
  45. 'https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/WXImage/%E9%80%89%E6%8B%A9%E7%A5%9E%E5%85%BD-%E9%B8%BE%E9%B8%9F%E9%A2%84%E8%A7%88%E5%9B%BE.png',
  46. 'https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/WXImage/%E8%A7%A3%E9%94%81%E7%A5%9E%E5%85%BD-%E5%BA%94%E9%BE%99%E9%A2%84%E8%A7%88%E5%9B%BE2.png',
  47. 'https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/WXImage/%E9%80%89%E6%8B%A9%E7%A5%9E%E5%85%BD-%E7%8B%BB%E7%8C%8A%E9%A2%84%E8%A7%88%E5%9B%BE.png',
  48. ],
  49. log:"123",
  50. },
  51. onLoad(){
  52. wx.setInnerAudioOption({
  53. obeyMuteSwitch:false
  54. })
  55. this.bgm = wx.createInnerAudioContext({});
  56. this.bgm.src = 'https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/WXBGM.MP3';
  57. this.bgm.play();
  58. this.bgm.loop=true;
  59. },
  60. onShow(){
  61. this.setData({log:'OnShow'});
  62. var that = this;
  63. this.bgm.play();
  64. wx.login({
  65. success: (res) => {
  66. if (res.code) {
  67. // 获取到用户的临时登录凭证 code,可以发送给服务器
  68. console.log('用户登录成功,code:', res.code);
  69. wx.request({
  70. url: 'https://api-fat1.ghz-tech.com/miniprogram-shanhaijing/v1/product/listInfo',
  71. method:'POST',
  72. header:{
  73. 'Content-Type':'application/json'
  74. },
  75. data:{
  76. topic:1,
  77. js_code:res.code,
  78. app_id:'wx9a280bbd81c64f56'
  79. },
  80. success:(res)=>{
  81. console.log('POST 请求成功', res.data);
  82. that.setData({log:'POST 请求成功'});
  83. var products2 = res.data.data.products;
  84. var modelImgs = this.data.modelImg;
  85. console.log(' 商品列表 ',products2[0].desc);
  86. for(var i =0;i<products2.length;i++){
  87. products2[i]["modelImg"] = modelImgs[i];
  88. var formattedNumber = products2[i].price/100;
  89. formattedNumber = parseFloat(formattedNumber).toFixed(2);
  90. products2[i].price = formattedNumber;
  91. var modelShowIndex = products2[i]["id"];
  92. if(products2[i].activate){
  93. that.setData({uiShowIndex:modelShowIndex});
  94. }
  95. }
  96. that.setData({products:products2});
  97. console.log(' 商品列表 ',this.data.products[0]);
  98. that.setData({UiShowModel_Bottom:true});
  99. },
  100. fail:function(err){
  101. console.error('POST 请求失败', err);
  102. var errorlog = err.toString();
  103. that.setData({log:errorlog});
  104. }
  105. });
  106. } else {
  107. console.log('登录失败!' + res.errMsg);
  108. }
  109. },
  110. });
  111. },
  112. onUnload(){
  113. this.bgm.stop();
  114. },
  115. handleReady: function({detail}) {
  116. this.setData({
  117. sceneWidth: detail.width,
  118. sceneHeight: detail.height,
  119. recordWidth: detail.width,
  120. recordHeight: detail.height,
  121. });
  122. },
  123. handleProgress: function({detail}) {
  124. console.log('assets progress', detail);
  125. this.setData({progressInfo: `${~~(detail.progress * 100)} %\n`});
  126. },
  127. handleLoaded: function({detail}) {
  128. console.log('assets loaded', detail);
  129. this.setData({loaded: true});
  130. },
  131. handlestr: function({detail}) {
  132. //console.log('assets handlestr', detail);
  133. this.setData({
  134. loadedSaoMiao: true,
  135. });
  136. },
  137. clickZhaoHuan(e){
  138. this.setData({zhaohuanstate:true});
  139. this.setData({paizhaostate:false});
  140. this.setData({luxiangstate:false});
  141. },
  142. clickPaiZhao(e){
  143. this.setData({zhaohuanstate:false});
  144. this.setData({paizhaostate:true});
  145. this.setData({luxiangstate:false});
  146. },
  147. clickLuXiang(e){
  148. this.setData({luxiangstate:true});
  149. this.setData({zhaohuanstate:false});
  150. this.setData({paizhaostate:false});
  151. },
  152. ClickzhaohuanSS(e){
  153. this.setData({zhaohuanstate:false});
  154. this.setData({uiMainView:false});
  155. this.setData({uiShowModelView:true});
  156. this.setData({uiShowNum:1});
  157. },
  158. Clickpaizhaoss(e){
  159. // this.capture();
  160. /* this.scene.share.captureToFriends({
  161. fileType: 'png',
  162. quality: 0.8
  163. });
  164. //const base64 = scene.share.captureToDataURL();
  165. if(supported){
  166. // 判断当前客户端是否支持分享系统
  167. // const supported = scene.share.supported;
  168. await this.scene.share.captureToFriends({
  169. fileType: this.data.captureType,
  170. quality: this.data.captureQuality
  171. });
  172. }*/
  173. //capate.capate();
  174. //this.setData({paizhaostate:false});
  175. if (this.data.recordState) {
  176. wx.showToast({
  177. title: '录屏中不允许!',
  178. });
  179. return;
  180. }
  181. if (this.data.captureState) {
  182. wx.showToast({
  183. title: '等待上次完成!',
  184. });
  185. return;
  186. }
  187. this.setData({captureState: 1});
  188. // hack,其实应该等待异步方法完成
  189. setTimeout(() => {
  190. this.setData({captureState: 0});
  191. }, 1000);
  192. },
  193. Clickstartluxiang(e){
  194. this.setData({isStartluxiang:true});
  195. this.setData({recordState: 1});
  196. },
  197. Clickcloseluxiang(e){
  198. this.setData({isStartluxiang:false});
  199. this.setData({recordState: 0});
  200. wx.showToast({
  201. title: '视频已保存至相册',
  202. });
  203. },
  204. changeCaptureState(e) {
  205. if (this.data.recordState) {
  206. wx.showToast({
  207. title: '录屏中不允许!',
  208. });
  209. return;
  210. }
  211. if (this.data.captureState) {
  212. wx.showToast({
  213. title: '等待上次完成!',
  214. });
  215. return;
  216. }
  217. this.setData({captureState: 1});
  218. // hack,其实应该等待异步方法完成
  219. setTimeout(() => {
  220. this.setData({captureState: 0});
  221. }, 1000);
  222. },
  223. changeRecordState(e) {
  224. this.setData({recordState: this.data.recordState ? 0 : 1});
  225. },
  226. clickCloseUIShow(e){
  227. this.setData({uiMainView:true});
  228. this.setData({zhaohuanstate:true});
  229. this.setData({uiShowModelView:false});
  230. },
  231. clickJiSuoModel(e){
  232. },
  233. changeMoel:function(event){
  234. var current2 = event.detail.current;
  235. this.setData({
  236. current:current2
  237. })
  238. },
  239. clickShowLeft(e){
  240. var leftoldIndex = this.data.uiShowNum;
  241. if(leftoldIndex ==0){
  242. }
  243. switch(this.data.uiShowIndex){
  244. case 0:
  245. this.setData({uiShowIndex:2});
  246. break;
  247. case 2:
  248. this.setData({uiShowIndex:1});
  249. break;
  250. case 1:
  251. this.setData({uiShowIndex:0});
  252. break;
  253. }
  254. let current = this.data.current;
  255. current = current > 0 ? current - 1 : 0;
  256. this.setData({
  257. current: current,
  258. });
  259. },
  260. clickShowRight(e){
  261. var oldIndex = this.data.uiShowIndex;
  262. oldIndex = oldIndex+1;
  263. var nIndex = oldIndex%3;
  264. this.setData({uiShowIndex:nIndex});
  265. let current = this.data.current;
  266. current = current < 2 ? current + 1 : 2; // 假设总共有3页
  267. this.setData({
  268. current: current,
  269. });
  270. },clickJiSuoModel(e){
  271. var that = this;
  272. wx.login({
  273. success: (res) => {
  274. if (res.code) {
  275. // 获取到用户的临时登录凭证 code,可以发送给服务器
  276. console.log('用户登录成功,code:', res.code);
  277. var modelId = this.data.products[this.data.current].id;
  278. console.log('当前ModelId ', modelId);
  279. wx.request({
  280. url: 'https://api-fat1.ghz-tech.com/miniprogram-shanhaijing/v1/order/prepay',
  281. method:'POST',
  282. header:{
  283. 'Content-Type':'application/json'
  284. },
  285. data:{
  286. shop_cart:[{
  287. id:modelId,
  288. count:1,
  289. }],
  290. js_code:res.code,
  291. app_id:'wx9a280bbd81c64f56'
  292. },
  293. success:function(res){
  294. console.log('POST 请求成功', res.data);
  295. var paySignStr = res.data.data.pay_Sign;
  296. console.log('即将调取微信支付',res.data.data.pay_Sign);
  297. wx.requestPayment({
  298. nonceStr: res.data.data.nonce_str,
  299. package: res.data.data.package,
  300. paySign: res.data.data.pay_sign,
  301. timeStamp: res.data.data.time_stamp,
  302. signType:res.data.data.sign_type,
  303. success(res){
  304. console.log( '微信支付请求成功',res );
  305. // 付款成功回调
  306. var products2 = that.data.products;
  307. products2[that.data.current].activate = true;
  308. that.setData({products:products2});
  309. console.log('AAAA ',that.data.products);
  310. var uiShowIndex2 = products2[that.data.current].id;
  311. that.setData({uiShowIndex:uiShowIndex2});
  312. },
  313. fail(err){
  314. console.log('微信支付请求失败',err);
  315. }
  316. })
  317. },
  318. fail:function(err){
  319. console.error('POST 请求失败', err);
  320. }
  321. });
  322. } else {
  323. console.log('登录失败!' + res.errMsg);
  324. }
  325. },
  326. });
  327. }
  328. });