@gt6/sdk 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +506 -2
- package/dist/core/types.d.ts +17 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/gt6-sdk.cjs.js +358 -1
- package/dist/gt6-sdk.cjs.js.map +1 -1
- package/dist/gt6-sdk.esm.js +357 -2
- package/dist/gt6-sdk.esm.js.map +1 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/forms.d.ts +56 -0
- package/dist/modules/forms.d.ts.map +1 -0
- package/dist/modules/users.d.ts +115 -0
- package/dist/modules/users.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/gt6-sdk.esm.js
CHANGED
@@ -726,9 +726,272 @@ class SettingsAPI {
|
|
726
726
|
}
|
727
727
|
}
|
728
728
|
|
729
|
+
class FormsAPI {
|
730
|
+
constructor(client) {
|
731
|
+
this.client = client;
|
732
|
+
}
|
733
|
+
/**
|
734
|
+
* 通用表单提交方法
|
735
|
+
* @param aliases 表单别名(如 'CONTACT', 'FEEDBACK' 等)
|
736
|
+
* @param email 用户邮箱
|
737
|
+
* @param fieldValue 表单字段值
|
738
|
+
* @param options 提交选项
|
739
|
+
*/
|
740
|
+
async submitForm(aliases, email, fieldValue, options) {
|
741
|
+
const config = this.client.getConfig();
|
742
|
+
const endpoint = options?.endpoint || '/api/platform/table';
|
743
|
+
const createSecret = options?.createSecret || 'Cmx349181!';
|
744
|
+
const submitData = {
|
745
|
+
platformId: config.platformId,
|
746
|
+
aliases,
|
747
|
+
email,
|
748
|
+
fieldValue,
|
749
|
+
createSecret
|
750
|
+
};
|
751
|
+
try {
|
752
|
+
const response = await fetch(`${config.baseUrl}${endpoint}`, {
|
753
|
+
method: 'POST',
|
754
|
+
headers: {
|
755
|
+
'Content-Type': 'application/json',
|
756
|
+
},
|
757
|
+
body: JSON.stringify(submitData)
|
758
|
+
});
|
759
|
+
const result = await response.json();
|
760
|
+
return {
|
761
|
+
success: response.ok && result.success !== false,
|
762
|
+
message: result.message || (response.ok ? '提交成功' : '提交失败'),
|
763
|
+
data: result.data,
|
764
|
+
code: result.code
|
765
|
+
};
|
766
|
+
}
|
767
|
+
catch (error) {
|
768
|
+
return {
|
769
|
+
success: false,
|
770
|
+
message: error instanceof Error ? error.message : '网络错误',
|
771
|
+
data: null
|
772
|
+
};
|
773
|
+
}
|
774
|
+
}
|
775
|
+
/**
|
776
|
+
* 联系表单提交
|
777
|
+
* @param formData 联系表单数据
|
778
|
+
*/
|
779
|
+
async submitContactForm(formData) {
|
780
|
+
return this.submitForm('CONTACT', formData.email, {
|
781
|
+
firstName: formData.firstName,
|
782
|
+
lastName: formData.lastName || '',
|
783
|
+
phone: formData.phone || '',
|
784
|
+
subject: formData.subject,
|
785
|
+
message: formData.message
|
786
|
+
});
|
787
|
+
}
|
788
|
+
/**
|
789
|
+
* 反馈表单提交
|
790
|
+
* @param formData 反馈表单数据
|
791
|
+
*/
|
792
|
+
async submitFeedbackForm(formData) {
|
793
|
+
return this.submitForm('FEEDBACK', formData.email, {
|
794
|
+
name: formData.name,
|
795
|
+
type: formData.type,
|
796
|
+
message: formData.message,
|
797
|
+
rating: formData.rating || 0
|
798
|
+
});
|
799
|
+
}
|
800
|
+
/**
|
801
|
+
* 注册表单提交
|
802
|
+
* @param formData 注册表单数据
|
803
|
+
*/
|
804
|
+
async submitRegistrationForm(formData) {
|
805
|
+
return this.submitForm('REGISTRATION', formData.email, {
|
806
|
+
username: formData.username,
|
807
|
+
password: formData.password,
|
808
|
+
confirmPassword: formData.confirmPassword,
|
809
|
+
agreeTerms: formData.agreeTerms
|
810
|
+
});
|
811
|
+
}
|
812
|
+
/**
|
813
|
+
* 自定义表单提交
|
814
|
+
* @param aliases 表单别名
|
815
|
+
* @param formData 表单数据对象
|
816
|
+
* @param emailField 邮箱字段名(默认为 'email')
|
817
|
+
*/
|
818
|
+
async submitCustomForm(aliases, formData, emailField = 'email') {
|
819
|
+
const email = formData[emailField];
|
820
|
+
if (!email) {
|
821
|
+
return {
|
822
|
+
success: false,
|
823
|
+
message: '邮箱地址是必需的'
|
824
|
+
};
|
825
|
+
}
|
826
|
+
// 移除邮箱字段,避免重复
|
827
|
+
const { [emailField]: _, ...fieldValue } = formData;
|
828
|
+
return this.submitForm(aliases, email, fieldValue);
|
829
|
+
}
|
830
|
+
}
|
831
|
+
|
832
|
+
/**
|
833
|
+
* 用户管理API模块
|
834
|
+
* 提供用户登录、注册等功能
|
835
|
+
*/
|
836
|
+
class UsersAPI {
|
837
|
+
constructor(client) {
|
838
|
+
this.client = client;
|
839
|
+
}
|
840
|
+
/**
|
841
|
+
* 用户登录
|
842
|
+
* @param loginData 登录数据
|
843
|
+
* @returns 登录响应
|
844
|
+
*/
|
845
|
+
async login(loginData) {
|
846
|
+
try {
|
847
|
+
const response = await this.client.request('/web/user/login', {
|
848
|
+
method: 'POST',
|
849
|
+
headers: {
|
850
|
+
'Content-Type': 'application/json',
|
851
|
+
},
|
852
|
+
body: JSON.stringify(loginData)
|
853
|
+
});
|
854
|
+
return response;
|
855
|
+
}
|
856
|
+
catch (error) {
|
857
|
+
return {
|
858
|
+
success: false,
|
859
|
+
message: error instanceof Error ? error.message : '登录请求失败'
|
860
|
+
};
|
861
|
+
}
|
862
|
+
}
|
863
|
+
/**
|
864
|
+
* 用户注册
|
865
|
+
* @param registerData 注册数据
|
866
|
+
* @returns 注册响应
|
867
|
+
*/
|
868
|
+
async register(registerData) {
|
869
|
+
try {
|
870
|
+
const response = await this.client.request('/web/user/register', {
|
871
|
+
method: 'POST',
|
872
|
+
headers: {
|
873
|
+
'Content-Type': 'application/json',
|
874
|
+
},
|
875
|
+
body: JSON.stringify(registerData)
|
876
|
+
});
|
877
|
+
return response;
|
878
|
+
}
|
879
|
+
catch (error) {
|
880
|
+
return {
|
881
|
+
success: false,
|
882
|
+
message: error instanceof Error ? error.message : '注册请求失败'
|
883
|
+
};
|
884
|
+
}
|
885
|
+
}
|
886
|
+
/**
|
887
|
+
* 保存用户数据到本地存储
|
888
|
+
* @param userData 用户数据
|
889
|
+
*/
|
890
|
+
saveUserData(userData) {
|
891
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
892
|
+
localStorage.setItem('userData', JSON.stringify(userData));
|
893
|
+
}
|
894
|
+
}
|
895
|
+
/**
|
896
|
+
* 从本地存储获取用户数据
|
897
|
+
* @returns 用户数据或null
|
898
|
+
*/
|
899
|
+
getUserData() {
|
900
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
901
|
+
const userDataStr = localStorage.getItem('userData');
|
902
|
+
if (userDataStr) {
|
903
|
+
try {
|
904
|
+
return JSON.parse(userDataStr);
|
905
|
+
}
|
906
|
+
catch (error) {
|
907
|
+
console.warn('解析用户数据失败:', error);
|
908
|
+
return null;
|
909
|
+
}
|
910
|
+
}
|
911
|
+
}
|
912
|
+
return null;
|
913
|
+
}
|
914
|
+
/**
|
915
|
+
* 清除本地存储的用户数据
|
916
|
+
*/
|
917
|
+
clearUserData() {
|
918
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
919
|
+
localStorage.removeItem('userData');
|
920
|
+
}
|
921
|
+
}
|
922
|
+
/**
|
923
|
+
* 检查用户是否已登录
|
924
|
+
* @returns 是否已登录
|
925
|
+
*/
|
926
|
+
isLoggedIn() {
|
927
|
+
const userData = this.getUserData();
|
928
|
+
return userData !== null && userData.token !== undefined;
|
929
|
+
}
|
930
|
+
/**
|
931
|
+
* 获取当前登录用户的token
|
932
|
+
* @returns token或null
|
933
|
+
*/
|
934
|
+
getToken() {
|
935
|
+
const userData = this.getUserData();
|
936
|
+
return userData?.token || null;
|
937
|
+
}
|
938
|
+
/**
|
939
|
+
* 获取当前登录用户信息
|
940
|
+
* @returns 用户信息或null
|
941
|
+
*/
|
942
|
+
getCurrentUser() {
|
943
|
+
const userData = this.getUserData();
|
944
|
+
if (userData) {
|
945
|
+
const { token, ...userInfo } = userData;
|
946
|
+
return userInfo;
|
947
|
+
}
|
948
|
+
return null;
|
949
|
+
}
|
950
|
+
/**
|
951
|
+
* 用户登出
|
952
|
+
*/
|
953
|
+
logout() {
|
954
|
+
this.clearUserData();
|
955
|
+
}
|
956
|
+
/**
|
957
|
+
* 记住用户登录信息
|
958
|
+
* @param username 用户名
|
959
|
+
* @param password 密码
|
960
|
+
*/
|
961
|
+
rememberLogin(username, password) {
|
962
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
963
|
+
localStorage.setItem('rememberedUsername', username);
|
964
|
+
localStorage.setItem('rememberedPassword', password);
|
965
|
+
}
|
966
|
+
}
|
967
|
+
/**
|
968
|
+
* 获取记住的登录信息
|
969
|
+
* @returns 记住的登录信息
|
970
|
+
*/
|
971
|
+
getRememberedLogin() {
|
972
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
973
|
+
const username = localStorage.getItem('rememberedUsername');
|
974
|
+
const password = localStorage.getItem('rememberedPassword');
|
975
|
+
if (username && password) {
|
976
|
+
return { username, password };
|
977
|
+
}
|
978
|
+
}
|
979
|
+
return null;
|
980
|
+
}
|
981
|
+
/**
|
982
|
+
* 清除记住的登录信息
|
983
|
+
*/
|
984
|
+
clearRememberedLogin() {
|
985
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
986
|
+
localStorage.removeItem('rememberedUsername');
|
987
|
+
localStorage.removeItem('rememberedPassword');
|
988
|
+
}
|
989
|
+
}
|
990
|
+
}
|
991
|
+
|
729
992
|
/**
|
730
993
|
* GT6 SDK 主类
|
731
|
-
*
|
994
|
+
* 提供文章、产品、设置、表单和用户管理相关的所有功能
|
732
995
|
*/
|
733
996
|
class GT6SDK {
|
734
997
|
constructor(config) {
|
@@ -736,6 +999,8 @@ class GT6SDK {
|
|
736
999
|
this.articles = new ArticlesAPI(client);
|
737
1000
|
this.products = new ProductsAPI(client);
|
738
1001
|
this.settings = new SettingsAPI(client);
|
1002
|
+
this.forms = new FormsAPI(client);
|
1003
|
+
this.users = new UsersAPI(client);
|
739
1004
|
}
|
740
1005
|
/**
|
741
1006
|
* 获取客户端实例(用于高级用法)
|
@@ -893,7 +1158,97 @@ class GT6SDK {
|
|
893
1158
|
async getPaymentMethodAttribute(methodId, attrName, paymentAlias) {
|
894
1159
|
return this.products.getPaymentMethodAttribute(methodId, attrName, paymentAlias);
|
895
1160
|
}
|
1161
|
+
/**
|
1162
|
+
* 24. 便捷方法:通用表单提交
|
1163
|
+
*/
|
1164
|
+
async submitForm(aliases, email, fieldValue, options) {
|
1165
|
+
return this.forms.submitForm(aliases, email, fieldValue, options);
|
1166
|
+
}
|
1167
|
+
/**
|
1168
|
+
* 25. 便捷方法:联系表单提交
|
1169
|
+
*/
|
1170
|
+
async submitContactForm(formData) {
|
1171
|
+
return this.forms.submitContactForm(formData);
|
1172
|
+
}
|
1173
|
+
/**
|
1174
|
+
* 26. 便捷方法:反馈表单提交
|
1175
|
+
*/
|
1176
|
+
async submitFeedbackForm(formData) {
|
1177
|
+
return this.forms.submitFeedbackForm(formData);
|
1178
|
+
}
|
1179
|
+
/**
|
1180
|
+
* 27. 便捷方法:自定义表单提交
|
1181
|
+
*/
|
1182
|
+
async submitCustomForm(aliases, formData, emailField) {
|
1183
|
+
return this.forms.submitCustomForm(aliases, formData, emailField);
|
1184
|
+
}
|
1185
|
+
/**
|
1186
|
+
* 28. 便捷方法:用户登录
|
1187
|
+
*/
|
1188
|
+
async login(username, password, platformId) {
|
1189
|
+
return this.users.login({ username, password, platformId });
|
1190
|
+
}
|
1191
|
+
/**
|
1192
|
+
* 29. 便捷方法:用户注册
|
1193
|
+
*/
|
1194
|
+
async register(username, password, platformId, ibcode) {
|
1195
|
+
return this.users.register({ username, password, platformId, ibcode });
|
1196
|
+
}
|
1197
|
+
/**
|
1198
|
+
* 30. 便捷方法:检查用户是否已登录
|
1199
|
+
*/
|
1200
|
+
isLoggedIn() {
|
1201
|
+
return this.users.isLoggedIn();
|
1202
|
+
}
|
1203
|
+
/**
|
1204
|
+
* 31. 便捷方法:获取当前登录用户信息
|
1205
|
+
*/
|
1206
|
+
getCurrentUser() {
|
1207
|
+
return this.users.getCurrentUser();
|
1208
|
+
}
|
1209
|
+
/**
|
1210
|
+
* 32. 便捷方法:获取当前登录用户的token
|
1211
|
+
*/
|
1212
|
+
getToken() {
|
1213
|
+
return this.users.getToken();
|
1214
|
+
}
|
1215
|
+
/**
|
1216
|
+
* 33. 便捷方法:用户登出
|
1217
|
+
*/
|
1218
|
+
logout() {
|
1219
|
+
return this.users.logout();
|
1220
|
+
}
|
1221
|
+
/**
|
1222
|
+
* 34. 便捷方法:保存用户数据
|
1223
|
+
*/
|
1224
|
+
saveUserData(userData) {
|
1225
|
+
return this.users.saveUserData(userData);
|
1226
|
+
}
|
1227
|
+
/**
|
1228
|
+
* 35. 便捷方法:获取用户数据
|
1229
|
+
*/
|
1230
|
+
getUserData() {
|
1231
|
+
return this.users.getUserData();
|
1232
|
+
}
|
1233
|
+
/**
|
1234
|
+
* 36. 便捷方法:记住登录信息
|
1235
|
+
*/
|
1236
|
+
rememberLogin(username, password) {
|
1237
|
+
return this.users.rememberLogin(username, password);
|
1238
|
+
}
|
1239
|
+
/**
|
1240
|
+
* 37. 便捷方法:获取记住的登录信息
|
1241
|
+
*/
|
1242
|
+
getRememberedLogin() {
|
1243
|
+
return this.users.getRememberedLogin();
|
1244
|
+
}
|
1245
|
+
/**
|
1246
|
+
* 38. 便捷方法:清除记住的登录信息
|
1247
|
+
*/
|
1248
|
+
clearRememberedLogin() {
|
1249
|
+
return this.users.clearRememberedLogin();
|
1250
|
+
}
|
896
1251
|
}
|
897
1252
|
|
898
|
-
export { ArticlesAPI, GT6Client, GT6Error, GT6SDK, ProductsAPI, SettingsAPI, GT6SDK as default };
|
1253
|
+
export { ArticlesAPI, FormsAPI, GT6Client, GT6Error, GT6SDK, ProductsAPI, SettingsAPI, UsersAPI, GT6SDK as default };
|
899
1254
|
//# sourceMappingURL=gt6-sdk.esm.js.map
|