modal.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /**
  2. * 函数 - 弹窗
  3. */
  4. const localeObj = {
  5. title: {
  6. "zh-Hans": "提示",
  7. "zh-Hant": "提示",
  8. "en": "Tips"
  9. },
  10. confirmText: {
  11. "zh-Hans": "确定",
  12. "zh-Hant": "確定",
  13. "en": "OK"
  14. },
  15. cancelText: {
  16. "zh-Hans": "取消",
  17. "zh-Hant": "取消",
  18. "en": "Cancel"
  19. },
  20. placeholderText: {
  21. "zh-Hans": "请输入",
  22. "zh-Hant": "請輸入",
  23. "en": "Please enter"
  24. }
  25. };
  26. export default {
  27. /**
  28. vk.alert("内容");
  29. vk.alert("内容","提示","好的",function(){
  30. });
  31. */
  32. alert: function(a = " ", b, c, d) {
  33. let locale = vk.getLocale();
  34. let obj = {
  35. title: localeObj.title[locale],
  36. confirmText: localeObj.confirmText[locale],
  37. placeholderText: localeObj.placeholderText[locale],
  38. content: a,
  39. showCancel: false
  40. };
  41. if (typeof d === 'function') {
  42. obj.title = b;
  43. obj.confirmText = c;
  44. obj.success = d;
  45. } else if (typeof c === 'function') {
  46. obj.title = b;
  47. obj.success = c;
  48. } else if (typeof b === 'function') {
  49. obj.success = b;
  50. } else if (b != undefined) {
  51. obj.title = b;
  52. if (c != undefined) {
  53. obj.confirmText = c;
  54. }
  55. }
  56. if (typeof obj.content === 'number') {
  57. obj.content = obj.content + "";
  58. } else if (typeof obj.content === 'object') {
  59. obj.content = JSON.stringify(obj.content);
  60. }
  61. return uni.showModal(obj);
  62. },
  63. /**
  64. vk.confirm("内容","提示","确定","取消",(res) => {
  65. if(res.confirm){
  66. }
  67. });
  68. */
  69. confirm: function(a, b, c, d, e) {
  70. let locale = vk.getLocale();
  71. let obj = {
  72. showCancel: true,
  73. cancelColor: "#999",
  74. title: localeObj.title[locale],
  75. confirmText: localeObj.confirmText[locale],
  76. cancelText: localeObj.cancelText[locale],
  77. placeholderText: localeObj.placeholderText[locale],
  78. };
  79. if (typeof a === "object") {
  80. obj = a;
  81. } else {
  82. if (typeof a === "string") {
  83. obj.content = a;
  84. }
  85. if (typeof e === 'function') {
  86. obj.title = b;
  87. obj.confirmText = c;
  88. obj.cancelText = d;
  89. obj.success = e;
  90. } else if (typeof d === 'function') {
  91. obj.title = b;
  92. obj.confirmText = c;
  93. obj.success = d;
  94. } else if (typeof c === 'function') {
  95. obj.title = b;
  96. obj.success = c;
  97. } else if (typeof b === 'function') {
  98. obj.success = b;
  99. } else if (b != undefined) {
  100. obj.title = b;
  101. if (c != undefined) {
  102. obj.confirmText = c;
  103. }
  104. }
  105. }
  106. return uni.showModal(obj);
  107. },
  108. /**
  109. vk.prompt("请输入","提示","确定","取消",function(res){
  110. if(res.confirm){
  111. console.log(res.content);
  112. }
  113. },"输入框内初始内容");
  114. */
  115. prompt: function(a, b, c, d, e, f) {
  116. let locale = vk.getLocale();
  117. let obj = {
  118. showCancel: true,
  119. editable: true,
  120. cancelColor: "#999",
  121. title: localeObj.title[locale],
  122. confirmText: localeObj.confirmText[locale],
  123. cancelText: localeObj.cancelText[locale],
  124. placeholderText: localeObj.placeholderText[locale],
  125. };
  126. if (typeof a === "object") {
  127. obj = a;
  128. } else {
  129. if (typeof a === "string") {
  130. obj.placeholderText = a;
  131. }
  132. if (typeof e === 'function') {
  133. obj.title = b;
  134. obj.confirmText = c;
  135. obj.cancelText = d;
  136. obj.success = e;
  137. obj.content = f;
  138. } else if (typeof d === 'function') {
  139. obj.title = b;
  140. obj.confirmText = c;
  141. obj.success = d;
  142. obj.content = e;
  143. } else if (typeof c === 'function') {
  144. obj.title = b;
  145. obj.success = c;
  146. obj.content = d;
  147. } else if (typeof b === 'function') {
  148. obj.success = b;
  149. obj.content = c;
  150. }
  151. }
  152. return uni.showModal(obj);
  153. },
  154. /**
  155. vk.toast("提示内容","none");
  156. */
  157. toast: function(a, b, c, d, e) {
  158. if (typeof a === 'number') {
  159. a = a.toString();
  160. } else if (typeof a === 'object') {
  161. a = JSON.stringify(a);
  162. }
  163. let title = a;
  164. let icon = "none";
  165. let image = "";
  166. let mask = false;
  167. let duration = 1500;
  168. let fn;
  169. if (typeof e !== "undefined") {
  170. if (typeof e == "function") fn = e;
  171. if (typeof e == "number") duration = e;
  172. if (typeof e == "boolean") mask = e;
  173. }
  174. if (typeof d !== "undefined") {
  175. if (typeof d == "function") fn = d;
  176. if (typeof d == "number") duration = d;
  177. if (typeof d == "boolean") mask = d;
  178. }
  179. if (typeof c !== "undefined") {
  180. if (typeof c == "function") fn = c;
  181. if (typeof c == "number") duration = c;
  182. if (typeof c == "boolean") mask = c;
  183. }
  184. if (typeof b !== "undefined") {
  185. if (typeof b == "function") fn = b;
  186. if (typeof b == "number") duration = b;
  187. if (typeof b == "boolean") mask = b;
  188. if (typeof b == 'string') {
  189. if (b == "ok") b = "success";
  190. if (b == "success" || b == "loading" || b == "none") {
  191. icon = b;
  192. } else {
  193. image = b;
  194. }
  195. }
  196. }
  197. return uni.showToast({
  198. title: title,
  199. icon: icon,
  200. image: image,
  201. mask: mask,
  202. duration: duration,
  203. success: function(res) {
  204. if (typeof fn === 'function') {
  205. setTimeout(function() {
  206. fn(res);
  207. }, duration);
  208. }
  209. }
  210. });
  211. },
  212. /**
  213. * 操作菜单
  214. vk.showActionSheet({
  215. title:"",
  216. list:["位置","@好友"],
  217. color:"rgb(0, 0, 0)",
  218. success:function(res){
  219. if(res.index==0){
  220. }else if(res.index==1){
  221. }
  222. }
  223. });
  224. */
  225. showActionSheet: function(object) {
  226. let vk = getApp().globalData.vk;
  227. let title = object.title;
  228. let list = object.list;
  229. let color = object.color || "#000000";
  230. let success = object.success;
  231. let fail = object.fail;
  232. let complete = object.complete;
  233. return uni.showActionSheet({
  234. itemList: list,
  235. itemColor: color,
  236. success: function(res) {
  237. let index = res.tapIndex;
  238. let text = list[index];
  239. let g = { index, text };
  240. console.log(g);
  241. if (typeof success == "function") success(g);
  242. },
  243. fail: function(res) {
  244. console.log(res);
  245. if (typeof fail == "function") fail(res);
  246. },
  247. complete: function(res) {
  248. if (typeof complete == "function") complete(res);
  249. }
  250. });
  251. },
  252. showLoading: function(obj) {
  253. if (typeof obj == "string") {
  254. let title = obj;
  255. obj = {
  256. title: title,
  257. mask: true
  258. };
  259. }
  260. uni.showLoading(obj);
  261. },
  262. hideLoading: function() {
  263. uni.hideLoading();
  264. },
  265. // 设置当前页面的loading变量的值
  266. setLoading: function(loading = true, obj = true) {
  267. try {
  268. if (typeof obj === "boolean") {
  269. let pages = getCurrentPages();
  270. let page = pages[pages.length - 1];
  271. let that = page.$vm;
  272. that.loading = loading;
  273. } else if (typeof obj === "object") {
  274. let { data, name, that } = obj;
  275. if (uni.vk) {
  276. if (!data) data = that;
  277. uni.vk.pubfn.setData(data, name, loading);
  278. }
  279. } else if (typeof obj === "string") {
  280. let pages = getCurrentPages();
  281. let page = pages[pages.length - 1];
  282. let that = page.$vm;
  283. let name = obj;
  284. that.vk.pubfn.setData(that, name, loading);
  285. }
  286. } catch (err) {}
  287. },
  288. }