linkmange.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','clipboard'], function ($, undefined, Backend, Table, Form,Clipboard) {
  2. var Controller = {
  3. index: function () {
  4. // 给表单绑定事件
  5. Controller.api.bindevent();
  6. },
  7. api: {
  8. bindevent: function () {
  9. var clipboard = new Clipboard('.btn-copy');
  10. clipboard.on('success', function (e) {
  11. e.clearSelection();
  12. Toastr.success('复制成功');
  13. });
  14. clipboard.on('error', function (e) {
  15. e.clearSelection();
  16. Toastr.error("复制失败");
  17. });
  18. Form.api.bindevent($("form[role=form]"), function(data, ret){
  19. //如果我们需要在提交表单成功后做跳转,可以在此使用location.href="链接";进行跳转
  20. $("#targetUrl").html(data);
  21. $(".btn-copy").removeClass("hidden");
  22. $(".btn-copy").attr("data-clipboard-text", data);
  23. }, function(data, ret){
  24. console.log(data);
  25. console.log(ret);
  26. return false;
  27. }, function(success, error){
  28. //bindevent的第三个参数为提交前的回调
  29. //如果我们需要在表单提交前做一些数据处理,则可以在此方法处理
  30. //注意如果我们需要阻止表单,可以在此使用return false;即可
  31. //如果我们处理完成需要再次提交表单则可以使用submit提交,如下
  32. Form.api.submit(this, success, error);
  33. });
  34. //获取链接:阅读页|最近阅读 (切换TAB)
  35. $(document).on("click", ".link_type", function () {
  36. $("#targetUrl").empty();
  37. var type = $(this).val();
  38. if (type == 0) {
  39. $("#targetUrl").html();
  40. $(".btn-copy").attr("data-clipboard-text", '');
  41. $(".readgroup").removeAttr("style");
  42. $(".readgroup input").removeAttr("disabled");
  43. }
  44. if (type == 1) {
  45. $("#targetUrl").html();
  46. $(".btn-copy").attr("data-clipboard-text", '');
  47. $(".readgroup").css("display", "none");
  48. $(".readgroup input").attr("disabled", "disabled");
  49. }
  50. })
  51. }
  52. }
  53. };
  54. return Controller;
  55. });