parent
7c07e356a3
commit
bf9169a08d
@ -0,0 +1,122 @@
|
||||
const app = getApp();
|
||||
import {triggerApi, Session} from "../../../js/api"
|
||||
const session = new Session("testAccount");
|
||||
|
||||
// to trigger api using a new session
|
||||
function api(name){
|
||||
return function({success, fail, complete, ...data}={}){
|
||||
return triggerApi({
|
||||
session, name, data, success, fail, complete
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Page({
|
||||
data: {
|
||||
github_url:"https://github.com/educoder-weapp/educoder_weapp.git",
|
||||
gitee_url:"https://gitee.com/educoder_weapp/educoder_weapp.git",
|
||||
identifier:"mkgya7vu",
|
||||
file_content:"",
|
||||
routes:[],
|
||||
base:"https://forge.educoder.net/projects/6295/repository/revisions/master/raw",
|
||||
eduImgDir: global.config.eduImgDir
|
||||
},
|
||||
onShareAppMessage(){
|
||||
return app.shareApp({
|
||||
title:"EduCoder教学-版本库"
|
||||
})
|
||||
},
|
||||
api(name){
|
||||
return ({success, fail, complete, ...data}={})=>{
|
||||
return api(name)({success, fail, complete, identifier:this.data.identifier, ...data})
|
||||
}
|
||||
},
|
||||
copyGitUrl(){
|
||||
wx.setClipboardData({
|
||||
data: this.data.gitee_url
|
||||
})
|
||||
},
|
||||
navTo({name, type}){
|
||||
console.log({name, type})
|
||||
let routes = JSON.parse(JSON.stringify(this.data.routes));
|
||||
routes.push({name, type});
|
||||
let api_name = type=='tree'?"repository":"file_content";
|
||||
let path = this.getCurrentPath(routes);
|
||||
if(type=='blob'){
|
||||
let match = name.match(/.*(\.[^\.]*$)/)
|
||||
if(match&&[".jpg", ".jpeg", ".png", ".bmp", ".gif", ".svg"].indexOf(match[1])!=-1){
|
||||
let content = `![${name}](${this.data.base}/${path})`;
|
||||
this.setData({content, routes})
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.api("shixuns."+api_name)({path})
|
||||
.then(res=>{
|
||||
if(type!='tree'){
|
||||
if(!name.endsWith(".md")){
|
||||
res.content = "```\n"+res.content+"\n```"
|
||||
}
|
||||
wx.showLoading({
|
||||
title: '加载中'
|
||||
})
|
||||
}
|
||||
console.log(res);
|
||||
this.setData({...res, routes},wx.hideLoading);
|
||||
}).catch(e=>{
|
||||
app.showError(e);
|
||||
})
|
||||
|
||||
},
|
||||
getCurrentPath(routes){
|
||||
routes = routes?routes:this.data.routes;
|
||||
return routes.map(i=>i.name).join("/")
|
||||
},
|
||||
navBack({level, delta}){
|
||||
if(delta)
|
||||
level = this.data.routes.length - delta;
|
||||
let routes = this.data.routes.slice(0, level);
|
||||
if(level>0&&routes[routes.length-1].type!="tree")//点击的是当前文件的路径,不执行
|
||||
return;
|
||||
let api_name = "repository";
|
||||
let path = this.getCurrentPath(routes);
|
||||
this.api("shixuns."+api_name)({path})
|
||||
.then(res=>{
|
||||
this.setData({...res, routes, content:""});
|
||||
}).catch(e=>{
|
||||
app.showError(e);
|
||||
})
|
||||
},
|
||||
onTapNavBack(){
|
||||
this.navBack({delta:1})
|
||||
},
|
||||
onTapFile(e){
|
||||
console.log(e);
|
||||
let {currentTarget:{dataset:{name, type}}} = e;
|
||||
this.navTo({name, type});
|
||||
},
|
||||
onTapRoute(e){
|
||||
let {currentTarget:{dataset:{level}}} = e;
|
||||
this.navBack({level});
|
||||
},
|
||||
onLoad(){
|
||||
app.cloudapi("reportPageHistory")({
|
||||
page: this.route,
|
||||
options: this.options,
|
||||
status: 200,
|
||||
scene: app.globalData.scene
|
||||
})
|
||||
let testAccount = global.accountManager.testAccount;
|
||||
api("accounts.login")(testAccount).then(res=>{
|
||||
this.api("shixuns.repository")().then(res=>{
|
||||
console.log(res);
|
||||
this.setData(res);
|
||||
})
|
||||
}).catch(e=>{
|
||||
wx.showToast({
|
||||
title: '获取失败',icon:"none"
|
||||
})
|
||||
})
|
||||
|
||||
},
|
||||
})
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"rich-md":"../../components/rich-md/rich-md",
|
||||
"mp-icon":"/weui-miniprogram/icon/icon"
|
||||
},
|
||||
"navigationBarTitleText": "开源版本库"
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<view>
|
||||
<view class="git-url-wrp flex-row" bindtap="copyGitUrl">
|
||||
<mp-icon icon="link" type="field" size="18"/> {{gitee_url}}
|
||||
</view>
|
||||
<view class="commit-info">
|
||||
<view class="commit-item flex-row" wx:for="{{commits}}">
|
||||
<image class="avatar" src="{{eduImgDir}}{{item.author.image_url}}"/>
|
||||
<view class="flex-col">
|
||||
<view>
|
||||
<text class="name">{{item.author.name}}</text>提交于<text class="time">{{item.time}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="title">{{item.title}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="route-wrp">
|
||||
<view class="route-item {{routes.length>0?'active':''}}" data-level="0" bindtap="onTapRoute">
|
||||
根目录
|
||||
</view>
|
||||
<view class="route-item {{routes.length!=(index+1)?'active':''}}" wx:for="{{routes}}" data-level="{{index+1}}" bindtap="onTapRoute">
|
||||
<text class="gap"> / </text>{{item.name}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="content">
|
||||
<view class="file-item nav-back" bindtap="onTapNavBack" wx:if="{{routes.length>0}}">
|
||||
<mp-icon icon="previous" size="20" color="#4CACFF" type="field"/>..(返回上一层)
|
||||
</view>
|
||||
<view class="file-content" hidden="{{!content}}">
|
||||
<rich-md nodes="{{content}}" base="{{base}}" type="markdown"/>
|
||||
</view>
|
||||
<view class="trees" hidden="{{content}}">
|
||||
<view class="file-item" wx:for="{{trees}}"
|
||||
data-type='{{item.type}}' data-name="{{item.name}}" bindtap="onTapFile">
|
||||
<iconfont type="{{item.type=='tree'?'wenjianjia':'wenjian'}}"
|
||||
color="#00b0f0" size="20"/>
|
||||
{{item.name}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
@ -0,0 +1,57 @@
|
||||
page{
|
||||
background: white;
|
||||
}
|
||||
.git-url-wrp{
|
||||
font-size: 13px;
|
||||
padding: 8px 4px;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
.commit-info{
|
||||
font-size: 13px;
|
||||
padding: 3px;
|
||||
}
|
||||
.commit-item{
|
||||
align-items: center;
|
||||
}
|
||||
.avatar{
|
||||
border-radius: 50%;
|
||||
height: 27px;
|
||||
width: 27px;
|
||||
margin: 0 12px 0 6px;
|
||||
}
|
||||
.commit-item .name{
|
||||
color: #40485b;
|
||||
}
|
||||
.commit-item .title{
|
||||
color: #005980;
|
||||
}
|
||||
.route-wrp{
|
||||
display: flex;
|
||||
overflow-x: scroll;
|
||||
padding: 4px 6px;
|
||||
border-bottom: 1rpx lightgray solid;
|
||||
border-top: 1rpx lightgray solid;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: white;
|
||||
z-index: 10000;
|
||||
font-size: 15px;
|
||||
}
|
||||
.route-item.active{
|
||||
color: #4CACFF;
|
||||
}
|
||||
.route-item{
|
||||
flex: none;
|
||||
color: #888;
|
||||
}
|
||||
.route-item>.gap{
|
||||
white-space: pre;
|
||||
}
|
||||
.trees{
|
||||
padding: 10px 8px;
|
||||
}
|
||||
.nav-back{
|
||||
padding-left: 10px;
|
||||
margin-top: 5px;
|
||||
color: dimgray;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
import parseWeb from "./parse"
|
||||
|
||||
const baseUrl = "https://forge.educoder.net";
|
||||
|
||||
export function run(){
|
||||
apiParse({name: "projects.repository", data:{project_id:6295, identifier:"pk8f3pmu2"},
|
||||
success:res=>{
|
||||
console.log(res);
|
||||
}
|
||||
})
|
||||
}
|
||||
const apiConfig = {
|
||||
projects: {
|
||||
repository:{url:"{project_id}/repository/{identifier}"}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function format(str, values) {
|
||||
return str.replace(/\{(.*?)\}/g, function (match, key) {
|
||||
return values[key] || "";
|
||||
});
|
||||
}
|
||||
|
||||
function apiParse({name, data, success, fail, complete}){
|
||||
let apis = name.split(/\./g);
|
||||
var api = apiConfig;
|
||||
var url = baseUrl;
|
||||
for(var i=0;i<apis.length;i++){
|
||||
api = api[apis[i]];
|
||||
if(i+1==apis.length){
|
||||
url += "/" + format(api.url, data);
|
||||
}else{
|
||||
url += '/'+apis[i];
|
||||
}
|
||||
}
|
||||
console.log(url);
|
||||
wx.request({
|
||||
url,
|
||||
success:res=>{
|
||||
try{
|
||||
res.data = parseWeb[name](res.data);
|
||||
success&&success(res);
|
||||
complete&&complete(res);
|
||||
}catch(e){
|
||||
console.error(e);
|
||||
fail&&fail(e);
|
||||
complete&&complete&&(e);
|
||||
}
|
||||
},
|
||||
fail: e=>{
|
||||
fail&&fail(e);
|
||||
complete&&complete(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
export default {
|
||||
"projects.repository": function(web){
|
||||
var data = {}
|
||||
console.log(web);
|
||||
var base = web.match(/<div class="repository_con top-info-project padding15 clearfix" style="line-height:1.9;">(.*)<\/div>/)[1];
|
||||
console.log(base)
|
||||
var match = base.match(/<input type="text" id="copy_rep_content" class="pro-fenzhi-input fl" value="(.*)"\/>/);
|
||||
console.log(match);
|
||||
data.git_url = match[1];
|
||||
console.log(data);
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import {run} from "../../js/api"
|
||||
Page({
|
||||
|
||||
data: {
|
||||
|
||||
},
|
||||
onLoad: function (options) {
|
||||
run();
|
||||
},
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<!--miniprogram/project/pages/project/project.wxml-->
|
||||
<text>miniprogram/project/pages/project/project.wxml</text>
|
@ -0,0 +1 @@
|
||||
/* miniprogram/project/pages/project/project.wxss */
|
Loading…
Reference in new issue