5
5
6
6
public class ToTempFilePath : Details
7
7
{
8
- private void Start ( )
9
- {
10
- LogCurrentOptions ( ) ;
11
- }
12
-
13
8
protected override void TestAPI ( string [ ] args )
14
9
{
15
- LogCurrentOptions ( ) ; // 执行API前打印当前值
16
10
LoadCanvasToTempFilePath ( ) ;
17
11
}
18
-
19
- /// <summary>
20
- /// 当下拉菜单值改变时的回调方法
21
- /// </summary>
22
- /// <param name="dropdownIndex">下拉菜单索引</param>
23
- /// <param name="optionIndex">选项索引</param>
24
- public new void OnDropdownValueChanged ( int dropdownIndex , int optionIndex )
25
- {
26
- base . OnDropdownValueChanged ( dropdownIndex , optionIndex ) ;
27
- string newValue = entrySO . optionList [ dropdownIndex ] . availableOptions [ optionIndex ] ;
28
- UpdateOption ( dropdownIndex , newValue ) ;
29
- LogCurrentOptions ( ) ;
30
- }
31
-
32
-
33
- private float GetOptionValue ( int optionIndex , float defaultValue = 0f )
34
- {
35
- if ( options != null && optionIndex < options . Length )
36
- {
37
- if ( float . TryParse ( options [ optionIndex ] , out float value ) )
38
- {
39
- return value ;
40
- }
41
- }
42
- return defaultValue ;
43
- }
44
-
45
- private string GetOptionString ( int optionIndex , string defaultValue = "" )
46
- {
47
- if ( options != null && optionIndex < options . Length )
48
- {
49
- return options [ optionIndex ] ;
50
- }
51
- return defaultValue ;
52
- }
53
-
54
12
private void LoadCanvasToTempFilePath ( )
55
- {
56
- var sys = WX . GetSystemInfoSync ( ) ;
57
- string sysInfo = string . Format (
58
- "屏幕信息:\n screenWidth:{0}\n screenHeight:{1}\n windowWidth:{2}\n windowHeight:{3}\n " ,
59
- sys . screenWidth , sys . screenHeight , sys . windowWidth , sys . windowHeight
60
- ) ;
61
-
62
- // 根据options数组的索引获取值
13
+ { // 根据options数组的索引获取值
63
14
float x = GetOptionValue ( 0 ) ;
64
15
float y = GetOptionValue ( 1 ) ;
65
16
float width = GetOptionValue ( 2 ) ;
@@ -69,7 +20,7 @@ private void LoadCanvasToTempFilePath()
69
20
string fileType = GetOptionString ( 6 , "png" ) ;
70
21
float quality = GetOptionValue ( 7 ) ;
71
22
72
- Debug . Log ( $ "Using values: x ={ x } , y ={ y } , width ={ width } , height ={ height } , destWidth ={ destWidth } , destHeight ={ destHeight } , fileType ={ fileType } , quality ={ quality } ") ;
23
+ string optionsInfo = $ "当前参数值: \n x ={ x } \n y ={ y } \n width ={ width } \n height ={ height } \n destWidth ={ destWidth } \n destHeight ={ destHeight } \n fileType ={ fileType } \n quality ={ quality } ";
73
24
74
25
WXCanvas . ToTempFilePath ( new WXToTempFilePathParam ( )
75
26
{
@@ -87,14 +38,35 @@ private void LoadCanvasToTempFilePath()
87
38
WX . ShowModal ( new ShowModalOption ( )
88
39
{
89
40
title = "截图成功" ,
90
- content = "临时文件路径:" + result . tempFilePath + " \n \n " + sysInfo ,
41
+ content = $ " { optionsInfo } \n \n 临时文件路径: { result . tempFilePath } " ,
91
42
showCancel = false ,
92
43
success = ( res ) =>
93
44
{
94
- WX . ShareAppMessage ( new ShareAppMessageOption ( )
45
+ WX . PreviewMedia ( new PreviewMediaOption ( )
46
+ {
47
+ sources = new [ ] { new MediaSource { url = result . tempFilePath , type = "image" } } ,
48
+ current = 0 ,
49
+ success = ( res ) =>
50
+ {
51
+ Debug . Log ( "预览成功" ) ;
52
+ } ,
53
+ fail = ( res ) =>
54
+ {
55
+ Debug . Log ( "预览失败" ) ;
56
+ }
57
+ } ) ;
58
+ var fileManager = WX . GetFileSystemManager ( ) ;
59
+ fileManager . Access ( new AccessParam ( )
95
60
{
96
- title = "这是你的标题" ,
97
- imageUrl = result . tempFilePath ,
61
+ path = result . tempFilePath ,
62
+ success = ( res ) =>
63
+ {
64
+ Debug . Log ( "文件存在" ) ;
65
+ } ,
66
+ fail = ( res ) =>
67
+ {
68
+ Debug . Log ( "文件不存在" ) ;
69
+ }
98
70
} ) ;
99
71
}
100
72
} ) ;
@@ -114,44 +86,4 @@ private void LoadCanvasToTempFilePath()
114
86
} ,
115
87
} ) ;
116
88
}
117
-
118
- // 打印当前选项的值
119
- private void LogCurrentOptions ( )
120
- {
121
- if ( options != null )
122
- {
123
- for ( int i = 0 ; i < options . Length ; i ++ )
124
- {
125
- Debug . Log ( $ "Option { i } : { options [ i ] } ") ;
126
- }
127
- }
128
- else
129
- {
130
- Debug . Log ( "Options array is null" ) ;
131
- }
132
- }
133
-
134
- // 更新指定索引的选项值
135
- public void UpdateOption ( int optionIndex , string value )
136
- {
137
- if ( options != null && optionIndex < options . Length )
138
- {
139
- options [ optionIndex ] = value ;
140
- }
141
- else
142
- {
143
- Debug . Log ( $ "Cannot update option { optionIndex } : Invalid index or options not initialized") ;
144
- }
145
- }
146
-
147
- // 更新所有选项值
148
- public void UpdateValues ( )
149
- {
150
- // 直接从entrySO中获取值并更新
151
- for ( int i = 0 ; i < entrySO . optionList . Count ; i ++ )
152
- {
153
- string value = entrySO . optionList [ i ] . availableOptions [ 0 ] ;
154
- UpdateOption ( i , value ) ; // 更新对应索引选项值
155
- }
156
- }
157
89
}
0 commit comments