62d22edb6f51b666fb21d1ded0ea7b4a-js.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php /*a:2:{s:54:"D:\phpEnv\www\SCM-API\app\admin\view\addons\index.html";i:1750736984;s:52:"D:\phpEnv\www\SCM-API\app\admin\view\layout\vue.html";i:1750736984;}*/ ?>
  2. import table from "http://yun.cn/assets/js/components/Table.js";
  3. import {rand} from "http://yun.cn/assets/js/util.js";
  4. //生成订单号
  5. function create_out_trade_no()
  6. {
  7. let date=new Date();
  8. let year=date.getFullYear();
  9. let month=date.getMonth()+1;
  10. let day=date.getDate();
  11. if(day<10){
  12. day='0'+day;
  13. }
  14. let hour=date.getHours();
  15. if(hour<10){
  16. hour='0'+hour;
  17. }
  18. let minute=date.getMinutes();
  19. if(minute<10){
  20. minute='0'+minute;
  21. }
  22. let seconds=date.getSeconds();
  23. if(seconds<10){
  24. seconds='0'+seconds;
  25. }
  26. let r=''+year+month+day+hour+minute+seconds+rand(10000,99999);
  27. return r;
  28. }
  29. function formatTime(seconds)
  30. {
  31. let interval = Math.floor(seconds / 31536000);
  32. if (interval >= 1) {
  33. return `${interval}年后`;
  34. }
  35. interval = Math.floor(seconds / 2592000);
  36. if (interval >= 1) {
  37. return `${interval}月后`;
  38. }
  39. interval = Math.floor(seconds / 86400);
  40. if (interval >= 1) {
  41. return `${interval}天后`;
  42. }
  43. interval = Math.floor(seconds / 3600);
  44. if (interval >= 1) {
  45. return `${interval}小时后`;
  46. }
  47. interval = Math.floor(seconds / 60);
  48. if (interval >= 1) {
  49. return `${interval}分钟后`;
  50. }
  51. return `${Math.floor(seconds)}秒后`;
  52. }
  53. export default{
  54. components:{'YunTable':table},
  55. data:{
  56. extend:{
  57. index_url: 'addons/index',
  58. multi_url: 'addons/multi'
  59. },
  60. type:Yunqi.data.type,
  61. tabsValue:'plugin',
  62. plain:'all',
  63. columns:[
  64. {field:"plain",visible:'none',operate:{form:'hidden',value:function (){return Yunqi.app.plain},filter:false}},
  65. {field:"name",title:"扩展名称"},
  66. {field:"type",title:"扩展类型",searchList:Yunqi.data.type,operate:false},
  67. {field:"author",title:"作者"},
  68. {field:"price",title:"价格",width: 80,formatter:function (data) {
  69. let tag=Yunqi.formatter.tag;
  70. if (data) {
  71. tag.type='primary';
  72. tag.value='¥'+data;
  73. }else{
  74. tag.type='success';
  75. tag.value='免费';
  76. }
  77. return tag;
  78. }},
  79. {field:"version",title:"版本号",width: 80},
  80. {field:"document",title:"说明文档",formatter: function (data){
  81. if(data) {
  82. let link=Yunqi.formatter.link;
  83. link.value = data;
  84. return link;
  85. }else{
  86. return '';
  87. }
  88. }},
  89. {field:"description",title:"简介",width: 300},
  90. {
  91. field:"local",
  92. title:"本地",
  93. width: 80,
  94. formatter: function (data){
  95. let tag=Yunqi.formatter.tag;
  96. if(data){
  97. tag.value='是';
  98. tag.type='success';
  99. }else{
  100. tag.value='否';
  101. tag.type='danger';
  102. }
  103. return tag;
  104. }
  105. },
  106. {
  107. field:"packed",
  108. title:"打包",
  109. width: 80,
  110. formatter:function (data,row){
  111. if(!row.local){
  112. return '';
  113. }
  114. let tag=Yunqi.formatter.tag;
  115. if(data){
  116. tag.value='是';
  117. tag.type='primary';
  118. }else{
  119. tag.value='否';
  120. tag.type='danger';
  121. }
  122. return tag;
  123. }
  124. },
  125. {
  126. field:"open",
  127. title:"开放",
  128. width: 80,
  129. formatter:function (data,row){
  130. if(!row.local){
  131. return '';
  132. }
  133. let sw=Yunqi.formatter.switch;
  134. sw.activeValue=1;
  135. sw.inactiveValue=0;
  136. sw.value=row.packed?data:0;
  137. sw.disabled=true;
  138. if(row.packed){
  139. sw.disabled=false;
  140. }
  141. return sw;
  142. }
  143. },
  144. {
  145. field: 'operate',
  146. title: __('操作'),
  147. direction:'column',
  148. width:100,
  149. action:{
  150. download:{
  151. text:__('下载'),
  152. type:'primary',
  153. tooltip:false,
  154. icon:'fa fa-download',
  155. method:'downloadAddon',
  156. visible:function (row) {
  157. return !row.download;
  158. }
  159. },
  160. install:{
  161. text:__('安装'),
  162. type:'primary',
  163. tooltip:false,
  164. icon:'fa fa-wrench',
  165. method:'installAddon',
  166. visible:function (row) {
  167. return row.download && !row.install;
  168. }
  169. },
  170. pack:{
  171. text:__('打包'),
  172. type:'primary',
  173. tooltip:false,
  174. icon:'fa fa-briefcase',
  175. method:'packAddon',
  176. visible:function (row) {
  177. return row.download && row.install && !row.packed;
  178. }
  179. },
  180. edit:{
  181. text:__('编辑'),
  182. type:'warning',
  183. tooltip:false,
  184. icon:'fa fa-edit',
  185. method:'editAddon',
  186. visible:function (row) {
  187. return row.local && row.is_author && !row.packed;
  188. }
  189. },
  190. uninstall:{
  191. text:__('卸载'),
  192. type:'danger',
  193. tooltip:false,
  194. icon:'fa fa-remove',
  195. method:'uninstallAddon',
  196. visible:function (row) {
  197. return row.install && row.packed;
  198. }
  199. },
  200. remove:{
  201. text:__('删除'),
  202. type:'danger',
  203. tooltip:false,
  204. icon:'fa fa-remove',
  205. method:'delAddon',
  206. visible:function (row) {
  207. return row.download && !row.install;
  208. }
  209. },
  210. },
  211. }
  212. ],
  213. buyDialog:{
  214. show:false,
  215. out_trade_no:'',
  216. transaction_id:'',
  217. expire_time:0,
  218. status:0,
  219. message:'',
  220. code_url:'',
  221. row:''
  222. }
  223. },
  224. onLoad:function (){
  225. setInterval(()=>{
  226. this.checkPayStatus();
  227. },2000)
  228. },
  229. methods:{
  230. changePlain:function (plain) {
  231. this.plain = plain;
  232. this.$refs.yuntable.submit();
  233. },
  234. packAddon:function(row) {
  235. Yunqi.ajax.post('addons/pack',row).then(res=>{
  236. this.$refs.yuntable.reload();
  237. });
  238. },
  239. editAddon:function (row){
  240. let that=this;
  241. Yunqi.api.open({
  242. title: __('修改本地扩展'),
  243. url: 'addons/create?id='+row.id,
  244. icon:'fa fa-edit',
  245. close:function (r) {
  246. if(r){
  247. that.$refs.yuntable.reload();
  248. }
  249. }
  250. });
  251. },
  252. downloadAddon:function(row){
  253. if(row.price>0){
  254. this.buyDialog.out_trade_no=create_out_trade_no();
  255. this.buyDialog.code_url=Yunqi.config.baseUrl+'addons/payCode?key='+row.key+'&out_trade_no='+this.buyDialog.out_trade_no;
  256. this.buyDialog.show=true;
  257. this.buyDialog.row=row;
  258. }else{
  259. Yunqi.ajax.post('addons/download', row).then(res=>{
  260. this.$refs.yuntable.reload();
  261. });
  262. }
  263. },
  264. payDownload:function (){
  265. let postdata={...this.buyDialog.row,transaction_id:this.buyDialog.transaction_id}
  266. Yunqi.ajax.post('addons/download',postdata).then(res=>{
  267. this.closeBuyDialog();
  268. this.$refs.yuntable.reload();
  269. });
  270. },
  271. checkPayStatus:function (){
  272. if(this.buyDialog.show){
  273. Yunqi.ajax.get('addons/checkPayStatus',{out_trade_no:this.buyDialog.out_trade_no,key:this.buyDialog.row.key}).then(res=>{
  274. if(res){
  275. this.buyDialog.transaction_id=res.transaction_id;
  276. this.buyDialog.expire_time=res.expire_time;
  277. this.buyDialog.message='支付成功';
  278. this.buyDialog.status=1;
  279. }
  280. });
  281. }
  282. },
  283. checkTransactionId:function (){
  284. let postdata={
  285. pack:this.buyDialog.row.pack,
  286. transaction_id:this.buyDialog.transaction_id
  287. };
  288. Yunqi.ajax.get('addons/checkTransactionId',postdata).then(res=>{
  289. this.buyDialog.status=res.status;
  290. this.buyDialog.expire_time=res.expire_time;
  291. if(res.status==0){
  292. this.buyDialog.message='交易单号不存在';
  293. }else{
  294. if(res.expire_time>0){
  295. this.buyDialog.message=formatTime(res.expire_time)+'过期';
  296. }else{
  297. this.buyDialog.message='交易单号已经过期';
  298. }
  299. }
  300. });
  301. },
  302. closeBuyDialog:function () {
  303. this.buyDialog={
  304. show:false,
  305. out_trade_no:'',
  306. transaction_id:'',
  307. expire_time:0,
  308. status:0,
  309. message:'',
  310. code_url:'',
  311. row:''
  312. }
  313. },
  314. installAddon:function(row)
  315. {
  316. Yunqi.ajax.post('addons/install',{key:row.key}).then(res=>{
  317. this.$refs.yuntable.reload();
  318. });
  319. },
  320. uninstallAddon:function(row)
  321. {
  322. let that=this;
  323. Yunqi.api.open({
  324. title: __('卸载扩展'),
  325. url: 'addons/uninstall?key='+row.key,
  326. icon:'fa fa-remove',
  327. close:function (r) {
  328. if(r){
  329. that.$refs.yuntable.reload();
  330. }
  331. }
  332. });
  333. },
  334. delAddon:function (row){
  335. let that=this;
  336. Yunqi.confirm('删除扩展将会清空掉所有文件,重新下载扩展可能会再次收取费用,你确定要删除吗?','提醒').then(res=>{
  337. Yunqi.ajax.post('addons/del',{key:row.key}).then(res=>{
  338. that.$refs.yuntable.reload();
  339. });
  340. });
  341. },
  342. createAddon:function(){
  343. let that=this;
  344. Yunqi.api.open({
  345. title: __('创建本地扩展'),
  346. url: 'addons/create',
  347. icon:'fa fa-plus',
  348. close:function (r) {
  349. if(r){
  350. that.$refs.yuntable.reload();
  351. }
  352. }
  353. });
  354. }
  355. }
  356. }