Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bookplayer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
bookplayer
Commits
bfed74f3
Commit
bfed74f3
authored
Apr 01, 2025
by
15011343103
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat
parent
94f8998e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
64 deletions
+34
-64
index.html
form/index.html
+1
-0
index.js
form/index.js
+33
-64
No files found.
form/index.html
View file @
bfed74f3
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
</head>
</head>
<body>
<body>
<div
id=
"app"
>
<div
id=
"app"
>
无需配置,请直接使用
</div>
</div>
</body>
</body>
<script
src=
"./index.js"
></script>
<script
src=
"./index.js"
></script>
...
...
form/index.js
View file @
bfed74f3
/**
* 通用接口请求方法
* @param {string} url - 接口地址
* @param {string} method - 请求方法 ('GET' 或 'POST')
* @param {object} data - 请求参数
* @param {function} successCallback - 成功回调函数
* @param {function} errorCallback - 错误回调函数
*/
function
request
(
url
,
method
=
'
GET
'
,
data
=
{},
successCallback
,
errorCallback
)
{
// 构建请求配置
const
config
=
{
url
:
url
,
type
:
method
.
toUpperCase
(),
headers
:
{
'
Authorization
'
:
auth_key
,
'
Content-Type
'
:
'
application/json
'
},
success
:
function
(
response
)
{
if
(
successCallback
&&
typeof
successCallback
===
'
function
'
)
{
successCallback
(
response
);
}
},
error
:
function
(
xhr
,
status
,
error
)
{
if
(
errorCallback
&&
typeof
errorCallback
===
'
function
'
)
{
errorCallback
(
error
);
}
else
{
console
.
error
(
'
Request failed:
'
,
error
);
}
}
};
// 根据请求方法处理数据
if
(
method
.
toUpperCase
()
===
'
GET
'
)
{
config
.
data
=
data
;
// GET 请求参数会自动转换为查询字符串
}
else
if
(
method
.
toUpperCase
()
===
'
POST
'
)
{
config
.
data
=
JSON
.
stringify
(
data
);
// POST 请求体转换为 JSON 字符串
}
// 发送请求
$
.
ajax
(
config
);
}
const
signObj
=
{
/*
appKey
:
"
9a7efe3f90
"
,
appSecret
:
"
bcbd5d350b3e568a29963d1b1d16ba
"
,
stmt
:
Date
.
now
(),
};
const
signStr
=
JSON
.
stringify
(
signObj
);
const
sign
=
CryptoJS
.
MD5
(
signStr
).
toString
();
let
auth_key
=
{
window.courseware.getData(callback,key); //用于获取数据
appKey
:
signObj
.
appKey
,
window.courseware.setData(data,callback,key); //用于存储数据
sign
,
var uploadUrl = window.courseware.uploadUrl(); //上传文件的路径
stmt
:
signObj
.
stmt
var uploadData = window.courseware.uploadData(); //上传文件必须要的参数
};
// 把auth_key转成base64
auth_key
=
btoa
(
JSON
.
stringify
(
auth_key
));
console
.
log
(
auth_key
);
*/
//对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱
var
key
=
"
h5_test
"
;
$
(
function
(){
window
.
courseware
.
getData
(
function
(
data
){
//数据加载完,才算页面加载完成
//获取数据
if
(
data
&&
data
.
test
){
$
(
"
[name='test']
"
).
val
(
data
.
test
);
}
//绑定点击事件
$
(
'
#save
'
).
on
(
'
click
'
,
function
(){
var
test
=
$
(
"
[name='test']
"
).
val
();
//保存新增或修改的数据
window
.
courseware
.
setData
({
test
:
test
},
function
(){
//保存数据也是异步的
alert
(
"
保存成功!
"
);
},
key
);
})
},
key
);
})
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment