swan.closeCommunityEditor

    Object object

    示例

    请使用百度APP扫码

    swan.closeCommunityEditor - 图3

    • 在 swan 文件中
    • 在 js 文件中
    1. data: {
    2. content: '原帖内容'
    3. },
    4. onLoad(e) {
    5. },
    6. openCommunityEditor() {
    7. swan.openCommunityEditor({
    8. contentPlaceholder: '请输入帖子正文',
    9. titlePlaceholder: '请输入标题',
    10. moduleList: ['title', 'image', 'emoji', 'target'],
    11. imageConf: {
    12. maxNum: 9,
    13. ratio: 1
    14. },
    15. navBarTitleText: '发布帖子',
    16. navBarTextStyle: 'black',
    17. navBarBackgroundColor: '#ffffff',
    18. confirmText: '发布',
    19. cancelText: '取消',
    20. cancelColor: '#666666',
    21. targetText: '话题/吧/版块',
    22. emojiPath: '../../emojidata',
    23. success: function (res) {
    24. // 将图片上传到服务器
    25. // swan.uploadFile({
    26. // url: 'https://smartprogram.baidu.com/xxx', // 仅为示例,并非真实的接口地址
    27. // filePath: res.tempFilePaths[0], // 要上传文件资源的路径
    28. // name: 'myfile',
    29. // success: function (res) {
    30. // console.log(res.statusCode);
    31. // // 上传成功关闭发布器
    32. // swan.closeCommunityEditor();
    33. // },
    34. // fail: function (err) {
    35. // console.log('错误码:' + err.errCode);
    36. // console.log('错误信息:' + err.errMsg);
    37. // }
    38. // });
    39. swan.closeCommunityEditor();
    40. swan.showToast({
    41. title: '发布成功',
    42. icon: 'none'
    43. });
    44. },
    45. console.log('openCommunityEditor fail', err);
    46. swan.closeCommunityEditor();
    47. complete: function (res) {
    48. console.log('openCommunityEditor complete', res);
    49. }
    50. });
    51. // 定时器模拟开发者的提示时机,真实时机可据业务场景触发
    52. let that = this;
    53. setTimeout(function () {
    54. swan.showModal({
    55. title: '更新提示',
    56. content: '您所评论的内容有更新,是否要回到原帖查看',
    57. success(res) {
    58. console.log(res)
    59. if (res.confirm) {
    60. swan.closeCommunityEditor();
    61. that.setData('content', '更新的内容')
    62. }
    63. else if(res.cancel) {
    64. console.log('用户点击了取消');
    65. }
    66. }
    67. });
    68. }, 5000);
    69. }
    70. });