searchCardList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var intervalRefresh = 0;
  5. var arrOrder = [
  6. {},
  7. { Name: "最近更新", Value: "ac.UpdateTime desc", CSS: "numberContainerFooter1121Select" },
  8. { Name: "最近添加", Value: "ac.MiaoguoCardID desc", },
  9. { Name: "较早添加", Value: "ac.MiaoguoCardID asc" },
  10. { Name: "练习较多", Value: "ac.LearnNumber desc,ac.MiaoguoCardID desc" },
  11. { Name: "练习较少", Value: "ac.LearnNumber,ac.MiaoguoCardID" },
  12. { Name: "最近练习", Value: "ac.LastTime desc" },
  13. ];
  14. Page({
  15. data: {
  16. HasPage: false,
  17. ArrOrder: arrOrder,
  18. OrderType: 1,
  19. CardType:2,
  20. },
  21. onLoad: function (options) {
  22. var that = this;
  23. var Search = "", IsToday = 0, IsCollect = 0;
  24. var count = 0;
  25. if (options.Count)
  26. count = options.Count;
  27. if (options.search) {
  28. Search = options.search;
  29. wx.setNavigationBarTitle({
  30. title: "搜索结果"
  31. });
  32. }
  33. else if (options.type == 1) {
  34. IsToday = 1;
  35. wx.setNavigationBarTitle({
  36. title: "未练完的题卡"
  37. });
  38. }
  39. else if (options.type == 2) {
  40. IsToday = 2;
  41. wx.setNavigationBarTitle({
  42. title: "练完的题卡"
  43. });
  44. }
  45. else if (options.IsCollect == 1) {
  46. wx.setNavigationBarTitle({
  47. title: "收藏夹"
  48. });
  49. IsCollect = 1;
  50. }
  51. else if (options.CardType != 2) {
  52. var title = "日常练习";
  53. if (options.CardType == 1)
  54. title = "紧急练习";
  55. else if (options.CardType == -1)
  56. title = "留白";
  57. wx.setNavigationBarTitle({
  58. title: title + "题卡",
  59. });
  60. that.setData({
  61. CardType: options.CardType,
  62. });
  63. }
  64. that.setData({
  65. IsCollect: IsCollect,
  66. Search: Search,
  67. IsToday: IsToday,
  68. Count: count,
  69. Containnerheight: main.getWindowHeight(),
  70. PageType: options.type,
  71. IsNew: options.IsNew,
  72. });
  73. },
  74. onShow: function () {
  75. var that = this;
  76. if (that.data.IsNew)
  77. that.onOrder({ currentTarget: { dataset: { value: 4 } } });
  78. else
  79. that.getList();
  80. //题卡主题色
  81. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  82. if (!arrColorIndex) {
  83. app.globalData.ColorIndex = common.random(1, 4);
  84. }
  85. else {
  86. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  87. }
  88. },
  89. onPullDownRefresh: function () {
  90. var that = this;
  91. if (!that.data.IsCollect && !that.data.IsToday) {
  92. app.globalData.CardList = [];
  93. that.gotoNextPage({ currentTarget: { dataset: { id: 0 } } });
  94. }
  95. wx.stopPullDownRefresh();
  96. },
  97. getList: function () {
  98. var that = this;
  99. var list = app.globalData.CardList;
  100. var len = 16;
  101. for (var i = 0; i < list.length; i++) {
  102. var item = list[i];
  103. item.ScrollLeft = 0;
  104. item.DeleteStr = "删除";
  105. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  106. if (item.Content[1].ContentStr.length > len)
  107. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  108. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  109. if (item.Content[2].ContentStr.length > len)
  110. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  111. var imageUrl = getImage(item.Content[1].Content);
  112. if (imageUrl.length == 0 && item.Content[2].Content)
  113. imageUrl = getImage(item.Content[2].Content);
  114. if (imageUrl.length == 0 && item.Content[3].Content)
  115. imageUrl = getImage(item.Content[3].Content);
  116. if (imageUrl.length > 0) {
  117. item.ImageUrlTemp = main.getTempImage(imageUrl);
  118. item.ImageUrlServer = imageUrl;
  119. }
  120. }
  121. if (!that.data.IsToday && !that.data.Search) {
  122. main.getData("GetUserCardCount?UserID=" + app.globalData.userInfo.UserID+"&CardType="+that.data.CardType+"&IsCollect="+that.data.IsCollect, function (data) {
  123. if (data) {
  124. that.setData({
  125. Count: data.CardNumber,
  126. });
  127. var hasPage = false;
  128. if (list.length < that.data.Count && list.length>=20 && that.data.IsToday == 0)
  129. hasPage = true;
  130. that.setData({
  131. List: list,
  132. HasPage: hasPage,
  133. });
  134. if (that.data.PageType === "3") {
  135. wx.redirectTo({
  136. url: './preview?type=show&id=' + list[0].MiaoguoCardID,
  137. })
  138. }
  139. }
  140. });
  141. }
  142. else if (that.data.Search) {
  143. that.setData({
  144. List: list,
  145. Count: list.length,
  146. HasPage: true,
  147. });
  148. }
  149. else {
  150. that.setData({
  151. Count: list.length,
  152. });
  153. var hasPage = false;
  154. if (list.length < that.data.Count && that.data.IsToday == 0)
  155. hasPage = true;
  156. that.setData({
  157. List: list,
  158. HasPage: hasPage,
  159. });
  160. }
  161. wx.hideLoading();
  162. function getImage(str) {
  163. var result = "";
  164. if (str.indexOf("[图") >= 0) {
  165. result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
  166. result = result.substring(result.indexOf("]") + 1);
  167. }
  168. //console.log(result);
  169. return result;
  170. }
  171. function replaceString(str) {
  172. //str = str.replace(/\[图]/g, "");
  173. //str = str.replace(/\[\/图\]/g, "");
  174. var str2 = "";
  175. if (str.indexOf("[读 src=") >= 0) {
  176. str2 = str.substr(str.indexOf("[读 src="));
  177. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  178. }
  179. str = str.replace(str2, "");
  180. if (str.indexOf("[读 src=") >= 0) {
  181. str2 = str.substr(str.indexOf("[读 src"));
  182. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  183. }
  184. str = str.replace(str2, "");
  185. str = str.replace(/\[读]/g, "");
  186. str = str.replace(/\[\/读\]/g, "");
  187. var str3 = "";
  188. if (str.indexOf("[图") >= 0) {
  189. str3 = str.substr(str.indexOf("[图"));
  190. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  191. }
  192. str = str.replace(str3, "");
  193. if (str.indexOf("[图") >= 0) {
  194. str3 = str.substr(str.indexOf("[图"));
  195. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  196. }
  197. str = str.replace(str3, "");
  198. str = str.replace(/\[线]/g, "");
  199. str = str.replace(/\[\/线\]/g, "");
  200. str = main.encryptUrl(str);
  201. return str;
  202. }
  203. },
  204. onPreview: function (e) {
  205. var id = e.currentTarget.dataset.id;
  206. wx.navigateTo({
  207. url: './preview?type=show&id=' + id,
  208. })
  209. },
  210. playPPT: function () {
  211. wx.navigateTo({
  212. url: './preview?type=play',
  213. })
  214. },
  215. onBindError: function (e) {
  216. var that = this;
  217. var id = e.currentTarget.dataset.id;
  218. var serverUrl = e.currentTarget.dataset.serverurl;
  219. wx.downloadFile({
  220. url: serverUrl, // 仅为示例,并非真实的资源
  221. success(res) {
  222. if (res.statusCode === 200) {
  223. main.saveTempImage(serverUrl, res.tempFilePath);
  224. }
  225. }
  226. });
  227. // clearTimeout(intervalRefresh);
  228. // intervalRefresh = setTimeout(function () {
  229. // that.getList();
  230. // }, 1000);
  231. },
  232. gotoNextPage: function (e) {
  233. wx.showLoading({
  234. title: '请稍候',
  235. });
  236. setTimeout(function () {
  237. wx.hideLoading();
  238. }, 5000);
  239. var that = this;
  240. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  241. var id = e.currentTarget.dataset.id;
  242. if (id && id > 0)
  243. url += "&PageID=" + id;
  244. if (that.data.CardType)
  245. url += "&CardType=" + that.data.CardType;
  246. if (that.data.Search)
  247. url += "&Key=" + that.data.Search;
  248. var orderType = that.data.OrderType;
  249. if (orderType)
  250. url += "&OrderType=" + arrOrder[orderType].Value;
  251. if (e.currentTarget.dataset.iscollect==1)
  252. url += "&IsCollect=1";
  253. main.getData(url, function (data) {
  254. if (data) {
  255. var list = app.globalData.CardList;
  256. for (var i = 0; i < data.List.length; i++) {
  257. data.List[i].LastTimeStr = common.formatDateCHS(data.List[i].LastTime);
  258. list.push(data.List[i]);
  259. }
  260. app.globalData.CardList = list;
  261. that.getList();
  262. if (data.List.length < 20) {
  263. that.setData({
  264. HasPage: false,
  265. });
  266. }
  267. if (orderType > 0) {
  268. wx.setNavigationBarTitle({
  269. title: "全部题卡:" + arrOrder[orderType].Name,
  270. });
  271. }
  272. }
  273. });
  274. },
  275. addCard: function () {
  276. wx.redirectTo({
  277. url: './add?type=add&id=0',
  278. });
  279. },
  280. onSearch: function () {
  281. wx.navigateBack({
  282. delta: 1,
  283. });
  284. },
  285. onOrder: function (e) {
  286. var that = this;
  287. var value = e.currentTarget.dataset.value;
  288. for (var i = 0; i < this.data.ArrOrder.length; i++) {
  289. if (i == value)
  290. this.data.ArrOrder[i].CSS = "numberContainerFooter1121Select";
  291. else
  292. this.data.ArrOrder[i].CSS = "";
  293. }
  294. this.setData({
  295. IsOrder: false,
  296. ArrOrder: this.data.ArrOrder,
  297. OrderType: value,
  298. });
  299. if (!that.data.IsCollect && !that.data.IsToday) {
  300. app.globalData.CardList = [];
  301. that.gotoNextPage({ currentTarget: { dataset: { id: 0, OrderType: value } } });
  302. }
  303. },
  304. showOrder: function () {
  305. this.setData({
  306. IsOrder: true,
  307. });
  308. },
  309. closeOrder: function () {
  310. this.setData({
  311. IsOrder: false,
  312. });
  313. },
  314. DeleteItem: function (e) {
  315. var that = this;
  316. var id = e.currentTarget.dataset.id;
  317. var list = this.data.List;
  318. var b = true;
  319. for (var i = 0; i < list.length; i++) {
  320. var item = list[i];
  321. if (id == item.MiaoguoCardID) {
  322. if (item.DeleteStr == "删除") {
  323. item.ScrollLeft = 160;
  324. item.DeleteStr = "确认删除";
  325. }
  326. else if (item.DeleteStr == "确认删除") {
  327. b = false;
  328. item.DeleteStr = "删除";
  329. item.ScrollLeft = 0;
  330. var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
  331. url += "&ID=" + id;
  332. main.getData(url, function (data) {
  333. var list = app.globalData.CardList;
  334. for (var i = 0; i < list.length; i++) {
  335. if (id == list[i].MiaoguoCardID) {
  336. list.splice(i, 1);
  337. break;
  338. }
  339. }
  340. app.globalData.CardList = list;
  341. that.setData({
  342. List: list,
  343. Count: --that.data.Count,
  344. });
  345. });
  346. }
  347. }
  348. else {
  349. item.DeleteStr = "删除";
  350. item.ScrollLeft = 0;
  351. }
  352. }
  353. if (b) {
  354. that.setData({
  355. List: list,
  356. });
  357. }
  358. },
  359. onShareAppMessage: function () {
  360. return {
  361. title: app.globalData.ShareTitle,
  362. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  363. imageUrl: app.globalData.ShareImage,
  364. }
  365. },
  366. })